Set up and use Proof of Stake (PoS)
This guide goes into detail on how to set up a Proof of Stake network with the kalychain, how to stake funds for nodes to become validators and how to unstake funds.
Currently, there is no limit to the number of validators that can stake funds on the ValidatorSet Smart Contract.
It holds the necessary testing scripts, ABI files and most importantly the ValidatorSet Smart Contract itself.
The only difference between setting up a PoS and PoA cluster is in the genesis generation part.
When generating the genesis file for a PoS cluster, an additional flag is needed
kalychain genesis --pos ...
To set the size of an epoch for a cluster (in blocks), when generating the genesis file, an additional flag is specified
kalychain genesis --epoch-size 50
This value specified in the genesis file that the epoch size should be
The default value for the size of an epoch (in blocks) is
The default epoch length in blocks (
100000) may be a long time to way for validator set updates. Considering that new blocks are added ~2s, it would take ~55.5h for the validator set to possibly change.
Setting a lower value for the epoch length ensures that the validator set is updated more frequently. :::
The ValidatorSet Smart Contract repo is a Hardhat project, which requires NPM.
To initialize it correctly, in the main directory run:
Scripts for interacting with the deployed ValidatorSet Smart Contract are located on the ValidatorSet Smart Contract repo.
.envfile with the following parameters in the Smart Contracts repo location:
Where the parameters are:
- JSONRPC_URL - the JSON-RPC endpoint for the running node
- PRIVATE_KEYS - private keys of the staker address
- VALIDATOR_CONTRACT_ADDRESS - the address of the ValidatorSet smart contract ( default
:::info ValidatorSet address The ValidatorSet Smart Contract is pre-deployed at address
Any kind of interaction with the staking mechanism is done through the ValidatorSet Smart Contract at the specified address.
In order to become part of the validator set, an address needs to stake a certain amount of funds above a threshold.
Currently, the default threshold for becoming part of the validator set is
ValidatorSet can be initiated by calling the
stakemethod of the ValidatorSet Smart Contract, and specifying a value
>= 10000000 KLC.
.envfile mentioned in the previous section has been set up, and a chain has been started in PoS mode, staking can be done with the following command in the ValidatorSet Smart Contract repo:
npm run stake
stakeHardhat script stakes a default amount of
1000000 Dogecoin, which can be changed by modifying the
If the funds being staked are
>= 1000000 Dogecoin, the validator set on the ValidatorSet Smart Contract is updated, and the address will be part of the validator set starting from the next epoch.
Addresses that have a stake can only unstake all of their funds at once.
.envfile mentioned in the previous section has been set up, and a chain has been started in PoS mode, unstaking can be done with the following command in the ValidatorSet Smart Contract repo:
npm run unstake
All addresses that stake funds are saved to the ValidatorSet Smart Contract.
.envfile mentioned in the previous section has been set up, and a chain has been started in PoS mode, fetching the list of validators can be done with the following command in the ValidatorSet Smart Contract repo:
npm run info