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
  • Submit the certificate to the blockchain with a transaction

Create a registration certificate:

cardano-cli stake-address registration-certificate \
--stake-verification-key-file stake.vkey \
--out-file stake.cert
Now we need include it in a transaction to post it to the blockchain. Let's use the build command to accomplish this task.

Query the utxo

cardano-cli query utxo --address $(cat payment.addr) --testnet-magic 2
TxHash TxIx Amount
30231e5cff4048ee20ee864c708ac304c64d4cccd6975d629d5b7a8b5fab7db3 1 5000000 lovelace + TxOutDatumNone
726f76b90b924b47f2cb8ab5a712c82b182a85800138bbc5294f53d517d25e7c 1 9989824599 lovelace + TxOutDatumNone

Build the transaction

Registering the stake address to the blockchain pays a transaction fee but also needs a deposit. We can check the protocol parameters to learn how much we need to pay as deposit. We can get the deposit back when we deregister the stake key.
cat protocol.json | grep stakeAddressDeposit
"stakeAddressDeposit": 400000,
cardano-cli transaction build-raw \
--tx-in 30231e5cff4048ee20ee864c708ac304c64d4cccd6975d629d5b7a8b5fab7db3#1 \
--tx-out $(cat payment.addr)+0 \
--fee 0 \
--certificate-file stake.cert \
--out-file tx.draft
Calculate the transaction fee
cardano-cli transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count 1 \
--tx-out-count 1 \
--witness-count 2 \
--testnet-magic 2 \
--protocol-params-file protocol.json
178745 Lovelace
Calculate the change, note that we will pay the deposit by subtracting "stakeAddressDeposit": 400000 from the change after paying the transaction fee.
expr 5000000 - 178745 - 400000
Build the transaction with all the data
cardano-cli transaction build-raw \
--tx-in 30231e5cff4048ee20ee864c708ac304c64d4cccd6975d629d5b7a8b5fab7db3#1 \
--tx-out $(cat payment.addr)+4421255 \
--fee 178745 \
--certificate-file stake.cert \
--out-file tx.raw
Sign the transaction, both with the payment.skey and the stake,skey
cardano-cli transaction sign \
--testnet-magic 2 \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--signing-key-file stake.skey \
--out-file tx.signed
And submit it to the blockchain
cardano-cli transaction submit \
--testnet-magic 2 \
--tx-file tx.signed
Now the blockchain knows about our stake address
cardano-cli query stake-address-info \
--testnet-magic 2 --address $(cat stake.addr)
"address": "stake_test1ur2fgtgynw9zsa99xqr9ftnxrydff95q07ch8xzte80cfxgf3jye0",
"delegation": null,
"rewardAccountBalance": 0
As you can see, our stake is not delegated yet to any stake pool. Let's fix that creating our own stake pool.
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.
Copy link
On this page
Create a registration certificate:
Query the utxo
Build the transaction