English
🌙
19. Retire your stake pool
First, generate the protocol-parameters.
block producer node
1
cardano-cli query protocol-parameters \
2
--mainnet \
3
--out-file $NODE_HOME/params.json
Copied!
Calculate the current epoch.
block producer node
1
startTimeGenesis=$(cat $NODE_HOME/${NODE_CONFIG}-shelley-genesis.json | jq -r .systemStart)
2
startTimeSec=$(date --date=${startTimeGenesis} +%s)
3
currentTimeSec=$(date -u +%s)
4
epochLength=$(cat $NODE_HOME/${NODE_CONFIG}-shelley-genesis.json | jq -r .epochLength)
5
epoch=$(( (${currentTimeSec}-${startTimeSec}) / ${epochLength} ))
6
echo current epoch: ${epoch}
Copied!
Find the earliest and latest retirement epoch that your pool can retire.
block producer node
1
poolRetireMaxEpoch=$(cat $NODE_HOME/params.json | jq -r '.poolRetireMaxEpoch')
2
echo poolRetireMaxEpoch: ${poolRetireMaxEpoch}
3
4
minRetirementEpoch=$(( ${epoch} + 1 ))
5
maxRetirementEpoch=$(( ${epoch} + ${poolRetireMaxEpoch} ))
6
7
echo earliest epoch for retirement is: ${minRetirementEpoch}
8
echo latest epoch for retirement is: ${maxRetirementEpoch}
Copied!
🚧
Example: if we are in epoch 39 and poolRetireMaxEpoch is 18,
  • the earliest epoch for retirement is 40 ( current epoch + 1).
  • the latest epoch for retirement is 57 ( poolRetireMaxEpoch + current epoch).
Let's pretend we wish to retire as soon as possible in epoch 40.
Create the deregistration certificate and save it as pool.dereg. Update the epoch to your desired retirement epoch, usually the earliest epoch or asap.
air-gapped offline machine
1
cardano-cli stake-pool deregistration-certificate \
2
--cold-verification-key-file $HOME/cold-keys/node.vkey \
3
--epoch <retirementEpoch> \
4
--out-file pool.dereg
Copied!
Copy pool.dereg to your hot environment.
Find your balance and UTXOs.
block producer node
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 tip of the blockchain to set the invalid-hereafter parameter properly.
block producer node
1
currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
2
echo Current Slot: $currentSlot
Copied!
Run the build-raw transaction command.
block producer node
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 pool.dereg \
7
--out-file tx.tmp
Copied!
Calculate the minimum fee:
block producer node
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.
block producer node
1
txOut=$((${total_balance}-${fee}))
2
echo txOut: ${txOut}
Copied!
Build the transaction.
block producer node
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 pool.dereg \
7
--out-file tx.raw
Copied!
Copy tx.raw to your cold environment.
Sign the transaction.
air-gapped offline machine
1
cardano-cli transaction sign \
2
--tx-body-file tx.raw \
3
--signing-key-file payment.skey \
4
--signing-key-file $HOME/cold-keys/node.skey \
5
--mainnet \
6
--out-file tx.signed
Copied!
Copy tx.signed to your hot environment.
Send the transaction.
block producer node
1
cardano-cli transaction submit \
2
--tx-file tx.signed \
3
--mainnet
Copied!
Pool will retire at the end of your specified epoch. In this example, retirement occurs at the end of epoch 40.
If you have a change of heart, you can create and submit a new registration certificate before the end of epoch 40, which will then overrule the deregistration certificate.
After the retirement epoch, you can verify that the pool was successfully retired with the following query which should return an empty result.
block producer node
1
cardano-cli query ledger-state --mainnet > ledger-state.json
2
jq -r '.esLState._delegationState._pstate._pParams."'"$(cat stakepoolid.txt)"'" // empty' ledger-state.json
Copied!
After retirement completes in 2 epochs,
Last modified 2mo ago
Copy link