0Chain
Search…
Staking on miners and sharders
0chain miner smart contract allows staking on the miner and sharder nodes to validate transactions and earn rewards. To start staking on miner and sharder nodes, miner and sharder ID's are required which can be fetched using below commands.

Listing all miners

./zwallet ls-miners list the miners retrieved using the Miner smart contract. Parameters can be viewed using ./zwallet ls-miners --help flag.
1
Get list of all active miners from Miner SC
2
3
Usage:
4
zwallet ls-miners [flags]
5
6
Flags:
7
-h, --help help for ls-miners
8
--json as JSON
9
Copied!
--jsonflag can be passed to retrieve miners as JSON data.
Command:
1
./zwallet ls-miners
Copied!
Sample Output:
1
- ID: cdb9b5a29cb5f48b350481694c4645c2db24500e3af210e22e2d10477a68bad2
2
- Host: one.devnet-0chain.net
3
- Port: 31203
4
- ID: 3d9a10dac6fb3903d4a5283a42ae07b29d8e5d228afcce9bfc14e3e9dbc82748
5
- Host: one.devnet-0chain.net
6
- Port: 31201
7
- ID: aaa721d5fbf4ca83e20c8c40874ebcb144b86f57173633ff1702968677c2fa98
8
- Host: one.devnet-0chain.net
9
- Port: 31202
Copied!

Listing all sharders

./zwallet ls-sharders list the sharders retrieved using the Miner smart contract. Parameters can be viewed using ./zwallet ls-sharders --help flag.
1
Get list of all active sharders from Miner SC
2
3
Usage:
4
zwallet ls-sharders [flags]
5
6
Flags:
7
--all include all registered sharders
8
-h, --help help for ls-sharders
9
--json as JSON
10
11
Copied!
--all flag can be passed to retrieve all the available sharders where as --jsonflag will retrieve sharders as JSON data.
Command:
1
./zwallet ls-sharders
Copied!
Sample output:
1
MagicBlock Sharders
2
ID: 5421a8d0c9302af3cc79ac7e79d0c35eb09e7a25cb555fb3d6de9ab9dfcbc21c
3
- N2NHost: five.devnet-0chain.net
4
- Host: five.devnet-0chain.net
5
- Port: 31102
6
ID: d438037cd4ca7acf3d7e40823a661a747a3fe1724921a98b4d90657d5a056195
7
- N2NHost: five.devnet-0chain.net
8
- Host: five.devnet-0chain.net
9
- Port: 31101
10
Copied!

Get the staking configuration

To find out the number of delegates and the minimum and maximum tokens that can be staked, query the config using ./zwallet mn-config command.
./zwallet mn-config command displays the configuration and current requirements for staking.
Command:
1
./zwallet mn-config
Copied!
Response:
1
view_change: 0
2
max_n: 8
3
min_n: 2
4
max_s: 3
5
min_s: 1
6
t_percent: 0.51
7
k_percent: 0.75
8
last_round: 4758531
9
max_stake: 100
10
min_stake: 0
11
interest_rate: 5.55e-07
12
reward_rate: 1
13
share_ratio: 0.8
14
block_reward: 0.21
15
max_charge: 0.5
16
epoch: 15000000
17
reward_decline_rate: 0.1
18
interest_decline_rate: 0.1
19
max_mint: 4000000
20
minted: 999303.9977045408
21
max_delegates: 200
22
Copied!
According to the response the max delegates allowed are 200, where as the minimum and maximum number of tokens that can be staked are 0 and 100.
Get the miner or sharder info for staking
./zwallet mn-info command can be used to get staking info for a particular sharder or miner.
Parameters for mn-info command can be viewed using ./zwallet mn-info --help
1
Usage:
2
zwallet mn-info [flags]
3
4
Flags:
5
-h, --help help for mn-info
6
--id string miner/sharder ID to get info for
7
Copied!
Here,--id flag requires a particular miner and sharder ID which can be fetched using the ls-minersor ls-sharders command. For demonstration we are using a particular miner id fetched using ls-miners command.
Command:
1
./zwallet mn-info --id 68ed8f16e1d50e3217425b3e98fb7a39e5d7201fe4b1dccfe8477b5c54761b24
2
Copied!
Response:
1
{
2
"simple_miner":{
3
"id":"68ed8f16e1d50e3217425b3e98fb7a39e5d7201fe4b1dccfe8477b5c54761b24",
4
"n2n_host":"five.devnet-0chain.net",
5
"host":"five.devnet-0chain.net",
6
"port":31102,
7
"path":"sharder02",
8
"public_key":"458170c28496333426f9866989f7b335564d13d00f50db503275e7ec50a008031764ba5df42c20c85d76e7fe7eda43f39afdb650b8ffa9ed340e6fc50c35ae22",
9
"short_name":"localhost.s02",
10
"build_tag":"50fb047353c4c3d268c0e0ebfd8e63f1d10c6813",
11
"total_stake":0,
12
"delegate_wallet":"68ed8f16e1d50e3217425b3e98fb7a39e5d7201fe4b1dccfe8477b5c54761b24",
13
"service_charge":0.1,
14
"number_of_delegates":10,
15
"min_stake":0,
16
"max_stake":1000000000000,
17
"stat":{
18
"sharder_rewards":1160553450000000
19
},
20
"node_type":"sharder",
21
"last_health_check":1619554377
22
},
23
"pending":{
24
"01978379a586de2882638345e215baaf8382093609d910da5ac1a833e2814f6f":{
25
"stats":{
26
"delegate_id":"133807913c66ec0b4342612f23fecd1852b456152433b8380cd2abcd411d4c07",
27
"high":0,
28
"low":-1,
29
"interest_paid":0,
30
"reward_paid":0,
31
"number_rounds":0,
32
"status":"PENDING"
33
},
34
"pool":{
35
"pool":{
36
"id":"01978379a586de2882638345e215baaf8382093609d910da5ac1a833e2814f6f",
37
"balance":10000000000
38
},
39
"lock":{
40
"delete_view_change_set":false,
41
"delete_after_view_change":0,
42
"owner":"ff12c78ee4a985b4fc2ac52ec8a24e9df2bd912636da15437b0eb7707b99abf4"
43
}
44
}
45
}
46
}
47
}
Copied!

Locking a stake on a node

Staking tokens on a miner or sharder nodes helps earning additional tokens over time. Tokens locked for staking can be unlocked anytime but you have to wait for the next view change cycle.
Note: If a node becomes offline, all stake pools are automatically unlocked and tokens are returned to wallets.
Stalking tokens can be locked using the ./zwallet mn-lock command. Parameters for locking the tokens can be viewed using the ./zwallet mn-lock --help.
1
Flags:
2
-h, --help help for mn-lock
3
--id string miner/sharder ID to lock stake for
4
--tokens float tokens to lock
5
Copied!
Here, miner /sharder id with the required number of tokens to be locked are required.
Command for locking 0.2 tokens:
1
./zwallet mn-lock --id cdb9b5a29cb5f48b350481694c4645c2db24500e3af210e22e2d10477a68bad2 --tokens 0.2
Copied!
Response:
1
locked with: b488738546d84aed9d3dcb2bbe24c161bc4338638669e64e814631efd430fd85
Copied!
Note: If the locking of stakes is failing, verify the following.
  1. 1.
    Wallet has enough tokens
  2. 2.
    Node ID is valid
  3. 3.
    Node has available delegates

Getting the stake pools of a wallet

A stake pool allows multiple stakeholders (miners/sharders) to contribute to a blockchain in a manner that it increase their chances of earning staking rewards. Every stakeholder stakes tokens through its wallet in the stake pool.
To get the stake pool information of a particular wallet,./zwallet mn-user-info command can be used. Parameters for the ./zwallet mn-user-infocan be viewed using the --help tag.
1
Flags:
2
--client_id string get info for user, if empty, current user used, optional
3
-h, --help help for mn-user-info
4
--json as JSON
5
Copied!
Here, Client ID for a particular user is required which can be fetched from the wallet located in the .zcn directory. As mentioned above --client_id flag is optional and if you do not specify a particular wallet client_id. It will find the stake pool related to wallet config in default wallet.json file.
Command:
1
./zwallet mn-user-info
Copied!
Response:
1
- node: 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee (miner)
2
- pool_id: 77f7006f3ef89b5bc88016fbf9bc636cdb9c38425fa0e88940e4f99ddcf5be57
3
balance: 0.2
4
interests paid: 0.000000444
5
rewards paid: 59.5728
6
status: active
7
stake %: 100 %
8
Copied!
On a successful response, you will see the staked miner/sharder nodes and the amount of tokens locked with that particular wallet. The response output can also be formatted in JSON data using the --json flag.

Getting the stake pool info

./zwallet mn-pool-info command can be used to get stake pool info for a particular miner/sharder. Parameters can be viewed using the ./zwallet mn-pool-info --help
1
Flags:
2
-h, --help help for mn-pool-info
3
--id string miner/sharder ID to get info for
4
--pool_id string pool ID to get info for
5
Copied!
--id flag requires miner/sharder ID which can be fetched using ls-miners or ls-sharders command,pool_id is generated when you lock stake tokens for a miner/sharder node, you can copy the pool_id from the response text or can view it using mn-user-info command.
Command:
1
./zwallet mn-pool-info --id 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee --pool_id 77f7006f3ef89b5bc88016fbf9bc636cdb9c38425fa0e88940e4f99ddcf5be57
Copied!
Formatted Response:
1
{
2
"stats":{
3
"delegate_id":"822700aa95b6719281999c66d49764e6a258ff3bf259b83a62353615fd904829",
4
"high":0,
5
"low":-1,
6
"interest_paid":0,
7
"reward_paid":0,
8
"number_rounds":0,
9
"status":"PENDING"
10
},
11
"pool":{
12
"pool":{
13
"id":"b488738546d84aed9d3dcb2bbe24c161bc4338638669e64e814631efd430fd85",
14
"balance":10000000000
15
},
16
"lock":{
17
"delete_view_change_set":false,
18
"delete_after_view_change":0,
19
"owner":"822700aa95b6719281999c66d49764e6a258ff3bf259b83a62353615fd904829"
20
}
21
}
22
}
Copied!

Unlocking a stake on node

Staking tokens can be unlocked using the ./zwallet mn-unlock command. Parameters for locking the tokens can be viewed using the ./zwallet mn-unlock --help
1
Usage:
2
zwallet mn-unlock [flags]
3
4
Flags:
5
-h, --help help for mn-unlock
6
--id string miner/sharder ID to unlock pool of
7
--pool_id string pool ID to unlock
Copied!
Here, miner /sharder id with the pool ID to unlock the stake are required. Miner/sharder id can be fetched using ls-miners or ls-sharders command whereaspool_id is generated when you lock stake tokens for a miner/sharder node ,you can view it using mn-user-info command.
Command for unlocking would be:
1
./zwallet mn-unlock --id 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee --pool_id 77f7006f3ef89b5bc88016fbf9bc636cdb9c38425fa0e88940e4f99ddcf5be57
Copied!
Output:
1
tokens will be unlocked next VC
Copied!
Note: Tokens are released on the next view change cycle or at the next reward round.

Updating staking config of a node

./zwallet mn-update-settings command is used to update the staking config of a node. Parameters for the command can be viewed using --help flag.
1
Flags:
2
-h, --help help for mn-update-settings
3
--id string miner/sharder ID to update
4
--max_stake float max stake allowed
5
--min_stake float min stake allowed
6
--num_delegates int max number of delegate pools
7
Copied!
Miner/Sharder ID of the node is a required flag and can be fetched using ls-minersor ls-sharders command. Variables that can be updated are max stake, min stake and number of delegate pools.
Before updating the configuration lets get the default staking configuration for miner/sharder node using :
1
./zwallet mn-info --id 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee
Copied!
Response:
1
{
2
"simple_miner":{
3
"id":"110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee",
4
"n2n_host":"five.devnet-0chain.net",
5
"host":"five.devnet-0chain.net",
6
"port":31202,
7
"path":"miner02",
8
"public_key":"7f7a0515ae68eadee6eac5915519802911c7c7341d1ef23d913728aed47dc8090548a56031732d16916e203c4e41c2a32d022fe56758ba3956cc73b112f0961c",
9
"short_name":"localhost.m02",
10
"build_tag":"40058cb8b6aeeb95e61229702f29de4c7118ebaf",
11
"total_stake":0,
12
"delegate_wallet":"110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee",
13
"service_charge":0.1,
14
"number_of_delegates":10,
15
"min_stake":0,
16
"max_stake":1000000000000,
17
"stat":{
18
"generator_rewards":187795440000000
19
},
20
"node_type":"miner",
21
"last_health_check":1620947267
22
}
23
}
Copied!
In the above configuration min stake, max stake, number of delegate pools are 0,1000000000000 and 10 respectively. Lets update the miner/sharder node for 25 delegate pools, min and max stake for 1000,100000 using mn-update-settings.
1
./zwallet mn-update-settings --id 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee --max_stake 100000 --min_stake 1000 --num_delegates 5
Copied!
Note: Staking config can only be updated by the node's delegate wallet.