0Chain
Search…
Locking Tokens using ZWallet
ZWallet allows locking of tokens for a period of time to earn interest as additional ZCN tokens. The locking of tokens happens through an Interest Pool self executing contract.
There is a minimum amount of tokens which has to be locked for a minimum lock period for earning interest. The configuration for locking tokens can be viewed using the ./zwallet lockconfigcommand.

Getting lock config

./zwallet lockconfig shows the global configuration for locking tokens for interest such as minimum token and minimum lock period (duration).
Command:
1
./zwallet lockconfig
Copied!
Response:
1
Configuration:
2
{"ID":"cf8d0df9bd8cc637a4ff4e792ffe3686da6220c45f0e1103baa609f3f1751ef4","simple_global_node":{"max_mint":40000000000000000,"total_minted":6747913274207,"min_lock":10,"apr":0.1},"min_lock_period":60000000000}
3
Copied!

Locking tokens

./zwallet lock command is used to lock tokens for interest. The tokens are deducted from the wallet balance and are available back in the wallet by unlocking. Unlocking of tokens is only possible when the lock duration has passed.
Parameters for lock command can be viewed using ./zwallet lock --help
1
Usage:
2
zwallet lock [flags]
3
4
Flags:
5
--durationHr int Duration Hours to lock
6
--durationMin int Duration Mins to lock
7
--fee float Transaction Fee
8
-h, --help help for lock
9
--tokens float Number to tokens to lock
10
Copied!
Here, lock duration for locking tokens in hours or minutes are required and has to be specified. Transaction fee is optional flag but can be specified depending upon the miner. Some might charge a minimum transaction fee. Lastly number of tokens to lock is a required flag.
The following command locks 0.2 token for 5 minutes with a transaction fee of 0.1.
1
./zwallet lock --durationHr 0 --durationMin 5 --tokens 0.2 --fee 0.1
Copied!
Output:
1
Tokens (0.200000) locked successfully
Copied!
Check your wallet balance using
1
./zwallet getbalance
Copied!
On a successful lock, 0.3 ZCN tokens should be deducted from your wallet.
To understand better how the tokens are locked for earning interest you can check our video demonstration here.

Getting locked tokens

./zbox getlockedtokens command is used to know the amount of locked tokens and how much interest is gained over time through locking.
Command:
1
./zwallet getlockedtokens
Copied!
Response:
1
Locked tokens:
2
{"stats":[{"pool_id":"121053df2f2508a640111b338d4d3b18914c7a27f864b74c7fd86820d0638527","start_time":1620859478,"duration":300000000000,"time_left":-745398808346,"locked":false,"apr":0.1,"tokens_earned":1897,"balance":2000000000}]}
3
Copied!
The response will specify whether tokens are locked through a locked variable which uses a boolean. time_left variable has a negative value which means lock duration has not passed. Tokens earned through locking and locked tokens balance is also specified.
Note: Don't forget to copypool_id at a safer place as it is required to unlock tokens at a later time.

Unlocking tokens

Once the lock duration has passed ,you can unlock tokens using ./zwallet unlockcommand. Parameters for unlock command can be viewed using ./zwallet unlock --help.
1
Flags:
2
--fee float Transaction Fee
3
-h, --help help for unlock
4
--pool_id string Pool ID - hash of the locked transaction
5
Copied!
Here,--pool_id is a required flag whereas --fee flag is optional. For demonstration lets unlock the tokens we locked in the lock tokens section. The pool_id can be viewed using the./zwallet getlockedtokenscommand.
To unlock tokens use:
1
./zwallet unlock --pool_id 121053df2f2508a640111b338d4d3b18914c7a27f864b74c7fd86820d0638527
Copied!
Response:
1
Unlock tokens success
Copied!
On a successful unlock, your wallet balance will include the tokens you earned as interest plus the amount of tokens you locked initially.