Register stake address in the blockchain
Before, we created our payment keys and address, which allow us to control our funds; we also created our stake keys and stake address, which allow us to participate in the protocol by delegating our stake or by creating a stake pool.
We need to register our stake key in the blockchain. To achieve this, we:
  • Create a registration certificate
  • Determine the Time-to-Live (TTL)
  • Calculate the fees and deposit
  • Submit the certificate to the blockchain with a transaction

Create a registration certificate:

1
cardano-cli stake-address registration-certificate \
2
--stake-verification-key-file stake.vkey \
3
--out-file stake.cert
Copied!
Once the certificate has been created, we must include it in a transaction to post it to the blockchain.

Determine the TTL

As before, to create the transaction you need to determine the TTL querying the tip and adding some slots to give you sufficient time to build the transaction.

Draft transaction

1
cardano-cli transaction build-raw \
2
--tx-in b64ae44e1195b04663ab863b62337e626c65b0c9855a9fbb9ef4458f81a6f5ee#1 \
3
--tx-out $(cat paymentwithstake.addr)+0 \
4
--ttl 0 \
5
--fee 0 \
6
--out-file tx.raw \
7
--certificate-file stake.cert
Copied!

Calculate fees and deposit

This transaction has only 1 input (the UTXO used to pay the transaction fee) and 1 output (our paymentwithstake.addr to which we are sending the change). This transaction has to be signed by both the payment signing key payment.skey and the stake signing key stake.skey; and includes the certificate stake.cert:
1
cardano-cli transaction calculate-min-fee \
2
--tx-body-file tx.raw \
3
--tx-in-count 1 \
4
--tx-out-count 1 \
5
--witness-count 1 \
6
--byron-witness-count 0 \
7
--testnet-magic 1097911063 \
8
--protocol-params-file protocol.json
9
​
10
> 171485
Copied!
In this transaction we have to not only pay transaction fees, but also include a deposit (which we will get back when we deregister the key) as stated in the protocol parameters:
The deposit amount can be found in the protocol.json under stakeAddressDeposit:
1
...
2
"stakeAddressDeposit": 2000000,
3
...
Copied!
Query the UTXO:
1
cardano-cli query utxo \
2
--address $(cat payment.addr) \
3
--testnet-magic 1097911063
4
​
5
> TxHash TxIx Lovelace
6
> ----------------------------------------------------------------------------------------
7
> b64ae44e1195b04663ab863b62337e626c65b0c9855a9fbb9ef4458f81a6f5ee 1 1000000000
Copied!
So if we had 1000 ada, to calculate the change to send back to payment.addr we run:
1
expr 1000000000 - 171485 - 2000000
2
​
3
> 997828515
Copied!

Submit the certificate with a transaction:

Build the transaction:
1
cardano-cli transaction build-raw \
2
--tx-in b64ae44e1195b04663ab863b62337e626c65b0c9855a9fbb9ef4458f81a6f5ee#1 \
3
--tx-out $(cat paymentwithstake.addr)+997828515 \
4
--ttl 987654 \
5
--fee 171485 \
6
--out-file tx.raw \
7
--certificate-file stake.cert
Copied!
Sign it:
1
cardano-cli transaction sign \
2
--tx-body-file tx.raw \
3
--signing-key-file payment.skey \
4
--signing-key-file stake.skey \
5
--testnet-magic 1097911063 \
6
--out-file tx.signed
Copied!
And submit it:
1
cardano-cli transaction submit \
2
--tx-file tx.signed \
3
--testnet-magic 1097911063
Copied!
Your stake key is now registered on the blockchain.
QUESTIONS AND FEEDBACK
If you have any questions and suggestions while taking the lessons please feel free to ask in the forum and we will respond as soon as possible.
Last modified 5mo ago