Registering the stake address and delegating
In this tutorial, you will learn how to delegate stake and get rewarded for it.
First, you need to register your stake key on the blockchain. This action incurs a deposit of two ada according to the protocol parameters:
To register the stake key, you first need to produce a registration certificate. Take a look at the cardano-cli stake-address
command:
You'd be interested to use registration-certificate
:
This is how it looks like:
Now you need to submit your certificate to the blockchain. Let's use the build
command. This time, you need to use a few more options to build the transaction. We will use --certificate-file
to include the registration certificate, and --witness-override
to specify that this will be signed by two witnesses – payment.skey
and stake.skey
:
Sign it using both keys:
You can now delegate your stake. For this, you need to create a delegation certificate. Let's take another look at the cardano-cli stake-address
command:
To produce the delegation certificate, you need to know the ID of the pool that you will delegate to. The example below delegates to the pool that processed the registration certificate:
Build, sign, and submit the transaction with the certificate:
The delegation cycle
The delegation cycle consists of four epochs.
The cycle begins when a stakeholder delegates their stake to a stake pool. This process involves the creation of a delegation certificate, which is subsequently included in a transaction and registered on the blockchain. In the example below, this occurs at any slot within Epoch N.
Then, the protocol captures a stake snapshot (stakedist) at the last slot of Epoch N,, recording three important pieces of information:
The balance of each stake key registered on the blockchain
To which stake pool each stake key is delegated
The parameters (pool cost, margin, pledge, etc) that each stake pool has set.
This snapshot is then used at the end of Epoch N+1 to randomly select the slot leaders for Epoch N+2. This process is the essence of Ouroboros as a proof-of-stake consensus algorithm: the bigger the stake, the more chances to become a slot leader.
During Epoch N+2, stake pools produce the blocks they are entitled to based on the slot leader election. Naturally, stake pools with greater control of stake will be entitled to a larger number of blocks.
In the transition between Epoch N+2 and Epoch N+3, a new snapshot registers the collected rewards. The protocol uses the stake distribution recorded at the end of Epoch N to calculate how much of the rewards belong to each stake key.
Finally, during the transition between Epoch N+3 and Epoch N+4, the protocol distributes rewards to all stake keys. These rewards appear in wallets at the beginning of Epoch N+4, are credited to the wallet's balance, and are considered part of the stake for the snapshot taken at the final slot of Epoch N+4.
Last updated