English
How to delegate to a Stakepool

0. Prerequisites

  • Both a payment and a stake key pair. Payment key should contain some ADA.

👩💻
1. Register Stake Address

Create a certificate, stake.cert, using the stake.vkey
1
cardano-cli stake-address registration-certificate \
2
--stake-verification-key-file stake.vkey \
3
--out-file stake.cert
Copied!
You need to find the slot tip of the blockchain.
1
currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
2
echo Current Slot: $currentSlot
Copied!
Find your balance and UTXOs.
1
cardano-cli query utxo \
2
--address $(cat payment.addr) \
3
--mainnet > fullUtxo.out
4
5
tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
6
7
cat balance.out
8
9
tx_in=""
10
total_balance=0
11
while read -r utxo; do
12
in_addr=$(awk '{ print $1 }' <<< "${utxo}")
13
idx=$(awk '{ print $2 }' <<< "${utxo}")
14
utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
15
total_balance=$((${total_balance}+${utxo_balance}))
16
echo TxHash: ${in_addr}#${idx}
17
echo ADA: ${utxo_balance}
18
tx_in="${tx_in} --tx-in ${in_addr}#${idx}"
19
done < balance.out
20
txcnt=$(cat balance.out | wc -l)
21
echo Total ADA balance: ${total_balance}
22
echo Number of UTXOs: ${txcnt}
Copied!
Find the stakeAddressDeposit value.
1
stakeAddressDeposit=$(cat $NODE_HOME/params.json | jq -r '.stakeAddressDeposit')
2
echo stakeAddressDeposit : $stakeAddressDeposit
Copied!
Registration of a stake address certificate (stakeAddressDeposit) costs 2000000 lovelace.
Run the build-raw transaction command
The invalid-hereafter value must be greater than the current tip. In this example, we use current slot + 10000.
1
cardano-cli transaction build-raw \
2
${tx_in} \
3
--tx-out $(cat payment.addr)+0 \
4
--invalid-hereafter $(( ${currentSlot} + 10000)) \
5
--fee 0 \
6
--out-file tx.tmp \
7
--certificate stake.cert
Copied!
Calculate the current minimum fee:
1
fee=$(cardano-cli transaction calculate-min-fee \
2
--tx-body-file tx.tmp \
3
--tx-in-count ${txcnt} \
4
--tx-out-count 1 \
5
--mainnet \
6
--witness-count 2 \
7
--byron-witness-count 0 \
8
--protocol-params-file params.json | awk '{ print $1 }')
9
echo fee: $fee
Copied!
Ensure your balance is greater than cost of fee + stakeAddressDeposit or this will not work.
Calculate your change output.
1
txOut=$((${total_balance}-${stakeAddressDeposit}-${fee}))
2
echo Change Output: ${txOut}
Copied!
Build your transaction which will register your stake address.
1
cardano-cli transaction build-raw \
2
${tx_in} \
3
--tx-out $(cat payment.addr)+${txOut} \
4
--invalid-hereafter $(( ${currentSlot} + 10000)) \
5
--fee ${fee} \
6
--certificate-file stake.cert \
7
--out-file tx.raw
Copied!
Sign the transaction with both the payment and stake secret keys.
1
cardano-cli transaction sign \
2
--tx-body-file tx.raw \
3
--signing-key-file payment.skey \
4
--signing-key-file stake.skey \
5
--mainnet \
6
--out-file tx.signed
Copied!
Send the signed transaction.
1
cardano-cli transaction submit \
2
--tx-file tx.signed \
3
--mainnet
Copied!

📄
2. Create a delegation certificate

Given its stake pool verification key file node.vkey , from your stakepool should have generated (and published) a stake pool ID:
1
cardano-cli stake-pool id \
2
--cold-verification-key-file node.vkey \
3
--output-format 'hex'
Copied!
Given the stake pool ID from your stakepool, run the following:
1
cardano-cli stake-address delegation-certificate \
2
--stake-verification-key-file stake.vkey \
3
--stake-pool-id <stake pool ID> \
4
--out-file deleg.cert
Copied!
You need to find the tip of the blockchain to set the ttl parameter properly.
1
currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
2
echo Current Slot: $currentSlot
Copied!
Find your balance and UTXOs.
1
cardano-cli query utxo \
2
--address $(cat payment.addr) \
3
--mainnet > fullUtxo.out
4
5
tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
6
7
cat balance.out
8
9
tx_in=""
10
total_balance=0
11
while read -r utxo; do
12
in_addr=$(awk '{ print $1 }' <<< "${utxo}")
13
idx=$(awk '{ print $2 }' <<< "${utxo}")
14
utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
15
total_balance=$((${total_balance}+${utxo_balance}))
16
echo TxHash: ${in_addr}#${idx}
17
echo ADA: ${utxo_balance}
18
tx_in="${tx_in} --tx-in ${in_addr}#${idx}"
19
done < balance.out
20
txcnt=$(cat balance.out | wc -l)
21
echo Total ADA balance: ${total_balance}
22
echo Number of UTXOs: ${txcnt}
Copied!
Run the build-raw transaction command.
1
cardano-cli transaction build-raw \
2
${tx_in} \
3
--tx-out $(cat payment.addr)+${total_balance} \
4
--invalid-hereafter $(( ${currentSlot} + 10000)) \
5
--fee 0 \
6
--certificate-file deleg.cert \
7
--out-file tx.tmp
Copied!
Calculate the minimum fee:
1
fee=$(cardano-cli transaction calculate-min-fee \
2
--tx-body-file tx.tmp \
3
--tx-in-count ${txcnt} \
4
--tx-out-count 1 \
5
--mainnet \
6
--witness-count 2 \
7
--byron-witness-count 0 \
8
--protocol-params-file params.json | awk '{ print $1 }')
9
echo fee: $fee
Copied!
Calculate your change output.
1
txOut=$((${total_balance}-${fee}))
2
echo txOut: ${txOut}
Copied!
Build the transaction.
1
cardano-cli transaction build-raw \
2
${tx_in} \
3
--tx-out $(cat payment.addr)+${txOut} \
4
--invalid-hereafter $(( ${currentSlot} + 10000)) \
5
--fee ${fee} \
6
--certificate-file deleg.cert \
7
--out-file tx.raw
Copied!
Sign the transaction.
1
cardano-cli transaction sign \
2
--tx-body-file tx.raw \
3
--signing-key-file payment.skey \
4
--signing-key-file stake.skey \
5
--mainnet \
6
--out-file tx.signed
Copied!
Send the transaction.
1
cardano-cli transaction submit \
2
--tx-file tx.signed \
3
--mainnet
Copied!
Congratulations! Your ADA is now successfully delegated to your chosen stakepool.
Last modified 3mo ago