Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose storagebalanceof as public #26

Open
wants to merge 6 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
362 changes: 221 additions & 141 deletions docs/advanced/storage-deposit-withdraw.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,173 +10,253 @@ toc={toc}
/>

## Overview
When depositing NEAR to the social DB contract, you can cover the storage cost for a specific account_id or the signer if account_id is not provided. You can also choose to pay the bare minimum deposit required for registering the account in the Social DB contract without any additional storage fees.

When depositing NEAR to the social DB contract, you can cover the storage cost for a specific account_id or the signer if account_id is not provided. You can also choose to pay the bare minimum deposit required for registering the account in the Social DB contract without any additional storage fees.

The signer account MUST have sufficient NEAR balance to cover the deposit.

## Checking Storage Balance

<Tabs
defaultValue="javascript-via-package-manager"
values={[
{ label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
{ label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
{ label: 'TypeScript', value: 'typescript' },
]}>
defaultValue="javascript-via-package-manager"
values={[
{ label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
{ label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
{ label: 'TypeScript', value: 'typescript' },
]}
>
<TabItem value="javascript-via-package-manager">

```js
const { Social } = require('@builddao/near-social-js');

const social = new Social();
const result = await social.storageBalanceOf({
accountId: 'alice.near',
signer, // an initialized near-api-js account
});
console.log(result);
/*
{
"available": "1000000000000000000000000",
"total": "1000000000000000000000000"
}
*/
```

</TabItem>

<TabItem value="javascript-via-cdn">

```js
var social = new NEARSocialSDK();

social.storageBalanceOf({
accountId: 'alice.near',
signer, // an initialized near-api-js account
}).then((result) => {
console.log(result);
/*
{
"available": "1000000000000000000000000",
"total": "1000000000000000000000000"
}
*/
});
```

</TabItem>

<TabItem value="typescript">

```typescript
import { Social } from '@builddao/near-social-js';

const social = new Social();
const result = await social.storageBalanceOf({
accountId: 'alice.near',
signer, // an initialized near-api-js account
});
console.log(result);
/*
{
"available": "1000000000000000000000000",
"total": "1000000000000000000000000"
}
*/
```

</TabItem>
</Tabs>

## Depositing NEAR To Storage

<Tabs
defaultValue="javascript-via-package-manager"
values={[
{ label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
{ label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
{ label: 'TypeScript', value: 'typescript' },
]}
>
<TabItem value="javascript-via-package-manager">

```js
const { Social } = require('@builddao/near-social-js');

const signer = await nearConnection.account('alice.near');
const accessKeys = await signer.getAccessKeys();
const social = new Social();
const transaction = await social.storageDeposit({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
registration_only: true, // set to true if you want to pay only the bare minimum deposit
account_id: 'bob.near', // optional, defaults to the signer account
deposit: '10000000000000000000000', // the amount to deposit in yoctoNEAR
});
// ...sign the returned transaction and post to the network
```
const { Social } = require('@builddao/near-social-js');

const signer = await nearConnection.account('alice.near');
const accessKeys = await signer.getAccessKeys();
const social = new Social();
const transaction = await social.storageDeposit({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
registration_only: true, // set to true if you want to pay only the bare minimum deposit
account_id: 'bob.near', // optional, defaults to the signer account
deposit: '10000000000000000000000', // the amount to deposit in yoctoNEAR
});
// ...sign the returned transaction and post to the network
```

</TabItem>

<TabItem value="javascript-via-cdn">
```js
var accessKeys;
var signer;
var social;

nearConnection.account('alice.near')
.then((_signer) => {
signer = _signer;

return signer.getAccessKeys();
})
.then((_accessKeys) => {
accessKeys = _accessKeys;
social = new NEARSocialSDK();

return social.storageDeposit({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
registration_only: true, // set to true if you want to pay only the bare minimum deposit
account_id: 'bob.near', // optional, defaults to the signer account
deposit: '10000000000000000000000', // the amount to deposit in yoctoNEAR

```js
var accessKeys;
var signer;
var social;

nearConnection.account('alice.near')
.then((_signer) => {
signer = _signer;

return signer.getAccessKeys();
})
.then((_accessKeys) => {
accessKeys = _accessKeys;
social = new NEARSocialSDK();

return social.storageDeposit({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
registration_only: true, // set to true if you want to pay only the bare minimum deposit
account_id: 'bob.near', // optional, defaults to the signer account
deposit: '10000000000000000000000', // the amount to deposit in yoctoNEAR
});
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
```
```

</TabItem>

<TabItem value="typescript">
```typescript
import { Social } from '@builddao/near-social-js';

const signer = await nearConnection.account('alice.near');
const accessKeys = await signer.getAccessKeys();
const social = new Social();
const transaction = await social.storageDeposit({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
registration_only: true, // set to true if you want to pay only the bare minimum deposit
account_id: 'bob.near', // optional, defaults to the signer account
deposit: '10000000000000000000000', // the amount to deposit in yoctoNEAR
});
// ...sign the returned transaction and post to the network
```

```typescript
import { Social } from '@builddao/near-social-js';

const signer = await nearConnection.account('alice.near');
const accessKeys = await signer.getAccessKeys();
const social = new Social();
const transaction = await social.storageDeposit({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
registration_only: true, // set to true if you want to pay only the bare minimum deposit
account_id: 'bob.near', // optional, defaults to the signer account
deposit: '10000000000000000000000', // the amount to deposit in yoctoNEAR
});
// ...sign the returned transaction and post to the network
```

</TabItem>
</Tabs>

# Withdrawing NEAR from Storage
## Withdrawing NEAR From Storage

<TOCInline
maxHeadingLevel={4}
toc={toc}
/>
<Tabs
defaultValue="javascript-via-package-manager"
values={[
{ label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
{ label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
{ label: 'TypeScript', value: 'typescript' },
]}
>
<TabItem value="javascript-via-package-manager">

## Overview
When withdrawing NEAR from the social DB contract, you can specify the amount to withdraw. If no amount is specified, all available NEAR is withdrawn.
```js
const { Social } = require('@builddao/near-social-js');

The signer account MUST have sufficient NEAR balance available for withdrawal.
const signer = await nearConnection.account('alice.near');
const accessKeys = await signer.getAccessKeys();
const social = new Social();
const transaction = await social.storageWithdraw({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
amount: '5000000000000000000000', // the amount to withdraw in yoctoNEAR, optional, defaults to all available balance
});
// ...sign the returned transaction and post to the network
```

<Tabs
defaultValue="javascript-via-package-manager"
values={[
{ label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
{ label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
{ label: 'TypeScript', value: 'typescript' },
]}>
<TabItem value="javascript-via-package-manager">

```js
const { Social } = require('@builddao/near-social-js');

const signer = await nearConnection.account('alice.near');
const accessKeys = await signer.getAccessKeys();
const social = new Social();
const transaction = await social.storageWithdraw({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
amount: '5000000000000000000000', // the amount to withdraw in yoctoNEAR, optional, defaults to all available balance
});
// ...sign the returned transaction and post to the network
```
</TabItem>

<TabItem value="javascript-via-cdn">
```js
var accessKeys;
var signer;
var social;

nearConnection.account('alice.near')
.then((_signer) => {
signer = _signer;

return signer.getAccessKeys();
})
.then((_accessKeys) => {
accessKeys = _accessKeys;
social = new NEARSocialSDK();

return social.storageWithdraw({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
amount: '5000000000000000000000', // the amount to withdraw in yoctoNEAR, optional, defaults to all available balance

```js
var accessKeys;
var signer;
var social;

nearConnection.account('alice.near')
.then((_signer) => {
signer = _signer;

return signer.getAccessKeys();
})
.then((_accessKeys) => {
accessKeys = _accessKeys;
social = new NEARSocialSDK();

return social.storageWithdraw({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
amount: '5000000000000000000000', // the amount to withdraw in yoctoNEAR, optional, defaults to all available balance
});
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
```
```

</TabItem>

<TabItem value="typescript">
```typescript
import { Social } from '@builddao/near-social-js';

const signer = await nearConnection.account('alice.near');
const accessKeys = await signer.getAccessKeys();
const social = new Social();
const transaction = await social.storageWithdraw({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
amount: '5000000000000000000000', // the amount to withdraw in yoctoNEAR, optional, defaults to all available balance
});
// ...sign the returned transaction and post to the network
```

```typescript
import { Social } from '@builddao/near-social-js';

const signer = await nearConnection.account('alice.near');
const accessKeys = await signer.getAccessKeys();
const social = new Social();
const transaction = await social.storageWithdraw({
blockHash: accessKeys[0].block_hash,
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer,
amount: '5000000000000000000000', // the amount to withdraw in yoctoNEAR, optional, defaults to all available balance
});
// ...sign the returned transaction and post to the network
```

</TabItem>
</Tabs>
Loading