In previous tutorials on adresses and transactions, we used "enterprise" addresses for simplicity. Such an address can receive payments, but it can not participate in staking.
Let us remedy this now and create staking keys and a staking address!
-
We assume that you have a running node and access to the command line interface. To create a staking key pair and save the verification key to
staking.vkey
and the signing key tostaking.skey
, we typecardano-cli shelley node key-gen-staking \ --verification-key-file staking.vkey \ --signing-key-file staking.skey
-
Once we have such a staking key pair, we can create staking addresses, addresses that can receive payments and participate in staking. To create such an address, we need our newly created staking key pair and a usual payment key pair, which we can create as explained here.
Assuming that we have the payment verification key in file
payment.vkey
and that we want to save our new staking address to fileaddr.staking
, we can invokecardano-cli
as follows:cardano-cli shelley address build-staking \ --payment-verification-key-file payment.vkey \ --staking-verification-key-file staking.vkey \ > addr.staking
We can use this address in the same way as before to receive and make payments: Others can send ada to this address, and we can spent from this address using the payment signing key (which in our example would be the signing key belonging to the verification key
payment.vkey
). -
While we are at it, let us also create a reward address associated with our staking keys, a special address for the purpose of receiving staking rewards:
cardano-cli shelley address build-reward \ --staking-verification-key-file staking.vkey \ > rewards
This will create a reward address for our staking key pair and save it to file
rewards
. -
For us to later be able to delegate our stake to one or more pools, we need to register our stake key. We first need to create an address registration certificate:
cardano-cli shelley stake-address registration-certificate \ --staking-verification-key-file staking.vkey \ --out-file staking.cert
-
Once the certificate has been created, we must include it in a transaction to post it to the blockchain.
We first calculate the fees needed for this transaction. As always, we would have to replace the
--testnet-magic 42
if we were to target a different network. We also have to choose--ttl
high enough, depending on where the tip of our blockchain currently is at. The transaction will have to be signed by both the payment signing key corresponding to the utxo used to pay the fees and by the stake signing key.cardano-cli shelley transaction calculate-min-fee \ --tx-in-count 1 \ --tx-out-count 1 \ --ttl 200000 \ --testnet-magic 42 \ --signing-key-file payment.skey \ --signing-key-file staking.skey \ --certificate staking.cert \ --protocol-params-file protocol.json > 171485
We will have to not only pay fees for this transaction, but also include a deposit (which we will get back when we deregister the key). The deposit amount can be found in the
protocol.json
under keykeyDeposit
:... "keyDeposit": 400000, ...
Assuming we have an utxo containing 1000 ada, we would get a change output of value
expr 1000000000 - 171485 - 400000 > 999428515
Now we can create the raw transaction:
cardano-cli shelley transaction build-raw \ --tx-in <the utxo used for paying fees and deposit> \ --tx-out $(cat addr.staking)+999428515 \ --ttl 200000 \ --fee 171485 \ --tx-body-file tx.raw \ --certificate staking.cert
We sign it:
cardano-cli shelley transaction sign \ --tx-body-file tx.raw --signing-key-file payment.skey \ --signing-key-file staking.skey \ --testnet-magic 42 \ --tx-file tx.signed
And submit it:
cardano-cli shelley transaction submit \ --tx-filepath tx.signed \ --testnet-magic 42