Skip to content

Commit

Permalink
docs: balances
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksandre committed Jul 24, 2024
1 parent 908afed commit 7061914
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 10 deletions.
7 changes: 4 additions & 3 deletions docs/.vuepress/configs/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ export const sidebar: Record<string, SidebarConfig> = {
{
text: 'SDK V2 [Alpha]',
children: [
'/build/sdk/v2/quick-start.md',
'/build/sdk/v2/collections.md',
'/build/sdk/v2/tokens.md',
'/build/sdk/v2/quick-start.md',
'/build/sdk/v2/balances.md',
'/build/sdk/v2/collections.md',
'/build/sdk/v2/tokens.md',
]
},
{
Expand Down
72 changes: 72 additions & 0 deletions docs/build/sdk/v2/balances.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Working with balances

## Prerequisite

Follow the [Getting started guide](./quick-start.md) to install required libraries, receive test network OPL tokens, and initialize SDK.

## Get balance

After receiving OPL tokens you can check your account's balance using SDK.

```ts:no-line-numbers
const balances = await unique.balance.get({
address: account.address
});
console.log(balances);
```

The output will resemble the following:

```ts:no-line-numbers
{
available: '270171775322286038926',
locked: '0',
free: '270171775322286038926',
total: '270171775322286038926',
reserved: '0',
staked: '0',
unstaked: '0',
canstake: '270171775322286038926',
vested: [],
decimals: 18,
tokenSymbol: 'OPL'
}
```

Let's understand balance meaning:

- `available`: the balance user can transfer. Most application should operate with this balance
- `locked`: the balance locked by staking or vesting
- `free`: the sum of `available` and `locked`
- `reserved`: the balance reserved by collator selection pallet
- `total`: the sum of `free` and `reserved` balance
- `staked`: the balance locked by staking
- `unstaked`: the balance that has been unstaked and awaiting unlocking period (~ 7 days)
- `canstake`: the balance user can stake
- `vested`: the balance locked by vesting pallet
- `decimals`: all balances are in the wei. This field shows what is the decimals part
- `tokenSymbol`: token symbol

## Transfer

The account can transfer tokens in `available` status.

```ts:no-line-numbers
await unique.balance.transfer({
amount: '100',
to: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
});
```

By default `amount` is set in wei.

It is also possible to specify transfer in coins.

```ts:no-line-numbers
await unique.balance.transfer({
amount: '100.44',
to: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
isAmountInCoins: true // <--- in this case the transfer amount will be 100.44e18
});
```
14 changes: 7 additions & 7 deletions docs/build/sdk/v2/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ There are three different collection modes in Unique Network:
You can specify the collection mode during the minting.

```ts:no-line-numbers
await unique.collection.create({
await sdk.collection.create({
name: "Test",
description: "Test collection",
symbol: "TST",
Expand All @@ -77,7 +77,7 @@ Every collection in Unique Network can have up to 64 properties - a unique set o
During the collection creation, you can set collection limits as follows:

```ts:no-line-numbers
const {result} = await unique.collection.create({
const {result} = await sdk.collection.create({
name: "Test",
description: "Test collection",
symbol: "TST",
Expand All @@ -94,7 +94,7 @@ Later you can set new properties or modify previously created ones.
```ts:no-line-numbers
...
await unique.collection.setProperties({
await sdk.collection.setProperties({
collectionId: result.collectionId,
properties: [{key: "C", value: "value C"}]
});
Expand All @@ -103,7 +103,7 @@ await unique.collection.setProperties({
### Now let's query our collection and check its properties

```ts:no-line-numbers
const collection = await unique.collection.get({idOrAddress: result.collectionId});
const collection = await sdk.collection.get({idOrAddress: result.collectionId});
console.log(collection.properties);
```
Expand Down Expand Up @@ -156,7 +156,7 @@ Every NFT token inside the collection can have properties. The list of allowed p
Let's look at how to specify them.

```ts:no-line-numbers
await unique.collection.create({
await sdk.collection.create({
name: "Test",
description: "Test collection",
symbol: "TST",
Expand All @@ -178,7 +178,7 @@ Every NFT token in the collection could have two properties:
The SDK also specifies some additional token properties related to Unique Schema. Let's check them.

```ts:no-line-numbers
const colleciton = await unique.collection.get({idOrAddress: collectionId})
const colleciton = await sdk.collection.get({idOrAddress: collectionId})
console.log(colleciton.tokenPropertyPermissions);
```
Expand All @@ -200,7 +200,7 @@ You can read more about collection limits in the [reference section](../../../re
And that is how you can set such limits:

```ts:no-line-numbers
await unique.collection.create({
await sdk.collection.create({
name: "Test",
description: "Test collection",
symbol: "TST",
Expand Down

0 comments on commit 7061914

Please sign in to comment.