English
Claiming Stake Pool Rewards
Let's walk through an example to claim your stake pools rewards.
Rewards are accumulated in the stake.addr address.
First, 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!
Set the amount to send in lovelaces.
Remember 1 ADA = 1,000,000 lovelaces.
block producer node
1
rewardBalance=$(cardano-cli query stake-address-info \
2
--mainnet \
3
--address $(cat stake.addr) | jq -r ".[0].rewardAccountBalance")
4
echo rewardBalance: $rewardBalance
Copied!
Set the destination address which is where you're moving your reward to. This address must have a positive balance to pay for transaction fees.
block producer node
1
destinationAddress=$(cat payment.addr)
2
echo destinationAddress: $destinationAddress
Copied!
Find your payment.addr balance, utxos and build the withdrawal string.
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}
23
24
withdrawalString="$(cat stake.addr)+${rewardBalance}"
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)+0 \
4
--invalid-hereafter $(( ${currentSlot} + 10000)) \
5
--fee 0 \
6
--withdrawal ${withdrawalString} \
7
--out-file tx.tmp
Copied!
Calculate the current 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}+${rewardBalance}))
2
echo Change Output: ${txOut}
Copied!
Build your 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
--withdrawal ${withdrawalString} \
7
--out-file tx.raw
Copied!
Copy tx.raw to your cold environment.
Sign the transaction with both the payment and stake secret keys.
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 stake.skey \
5
--mainnet \
6
--out-file tx.signed
Copied!
Copy tx.signed to your hot environment.
Send the signed transaction.
block producer node
1
cardano-cli transaction submit \
2
--tx-file tx.signed \
3
--mainnet
Copied!
Check if the funds arrived.
block producer node
1
cardano-cli query utxo \
2
--address ${destinationAddress} \
3
--mainnet
Copied!
You should see output similar to this showing your updated Lovelace balance with rewards.
1
TxHash TxIx Lovelace
2
----------------------------------------------------------------------------------------
3
100322a39d02c2ead....
Copied!
Copy link