Skip to content

5_register_key

cardano-node-wiki edited this page Jan 12, 2024 · 2 revisions

Register stake address on the blockchain

Stake address needs to be registered on the blockchain to be useful. Registering keys requires:

  • 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

Draft transaction

For the transaction draft, --tx.out, --invalid-hereafter and --fee can be set to zero.

cardano-cli transaction build-raw \
--tx-in b64ae44e1195b04663ab863b62337e626c65b0c9855a9fbb9ef4458f81a6f5ee#1 \
--tx-out $(cat payment.addr)+0 \
--invalid-hereafter 0 \
--fee 0 \
--out-file tx.draft \
--certificate-file stake.cert

Calculate fees

Compute the minimum fee.

Note that only one witness is required because Chapter 3.3 "we do not require a witness to register a stake address".

cardano-cli transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count 1 \
--tx-out-count 1 \
--witness-count 1 \
--byron-witness-count 0 \
--mainnet \
--protocol-params-file protocol.json

The output is the transaction fee in lovelace:

> 171485

Registering the stake address, not only pay transaction fees, but also includes a deposit (which you get back when deregister the key) as stated in the protocol parameters:

The deposit amount can be found in the protocol.json under stakeAddressDeposit, for example in Shelley Mainnet:

...
"stakeAddressDeposit": 2000000,
...

Query the UTXO of the address that pays for the transaction and deposit:

cardano-cli query utxo \
    --address $(cat payment.addr) \
    --mainnet

>                            TxHash                                 TxIx      Amount
> ----------------------------------------------------------------------------------------
> b64ae44e1195b04663ab863b62337e626c65b0c9855a9fbb9ef4458f81a6f5ee     1      1000000000 lovelace

Calculate the change to send back to payment address after including the deposit

expr 1000000000 - 171485 - 2000000

> 997828515

Submit the certificate with a transaction:

Build the transaction, this time include --invalid-hereafter and --fee

cardano-cli transaction build-raw \
--tx-in b64ae44e1195b04663ab863b62337e626c65b0c9855a9fbb9ef4458f81a6f5ee#1 \
--tx-out $(cat payment.addr)+997828515 \
--invalid-hereafter 987654 \
--fee 171485 \
--out-file tx.raw \
--certificate-file stake.cert

Sign it:

cardano-cli transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--mainnet \
--out-file tx.signed

And submit it:

cardano-cli transaction submit \
--tx-file tx.signed \
--mainnet

Your stake key is now registered on the blockchain.

Note--mainnet identifies the Cardano mainnet, for preproduction testnet use --testnet-magic 1 and for preview testnet use --testnet-magic 2

Clone this wiki locally