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
currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
echo Current Slot: $currentSlot
Set the amount to send in lovelaces.
Remember 1 ADA = 1,000,000 lovelaces.
block producer node
rewardBalance=$(cardano-cli query stake-address-info \
--mainnet \
--address $(cat stake.addr) | jq -r ".[0].rewardAccountBalance")
echo rewardBalance: $rewardBalance
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
destinationAddress=$(cat payment.addr)
echo destinationAddress: $destinationAddress
Find your payment.addr balance, utxos and build the withdrawal string.
block producer node
cardano-cli query utxo \
--address $(cat payment.addr) \
--mainnet > fullUtxo.out
tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
cat balance.out
while read -r utxo; do
type=$(awk '{ print $6 }' <<< "${utxo}")
if [[ ${type} == 'TxOutDatumNone' ]]
in_addr=$(awk '{ print $1 }' <<< "${utxo}")
idx=$(awk '{ print $2 }' <<< "${utxo}")
utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
echo TxHash: ${in_addr}#${idx}
echo ADA: ${utxo_balance}
tx_in="${tx_in} --tx-in ${in_addr}#${idx}"
done < balance.out
txcnt=$(cat balance.out | wc -l)
echo Total available ADA balance: ${total_balance}
echo Number of UTXOs: ${txcnt}
withdrawalString="$(cat stake.addr)+${rewardBalance}"
Run the build-raw transaction command.
block producer node
cardano-cli transaction build-raw \
${tx_in} \
--tx-out $(cat payment.addr)+0 \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee 0 \
--withdrawal ${withdrawalString} \
--out-file tx.tmp
Calculate the current minimum fee:
block producer node
fee=$(cardano-cli transaction calculate-min-fee \
--tx-body-file tx.tmp \
--tx-in-count ${txcnt} \
--tx-out-count 1 \
--mainnet \
--witness-count 2 \
--byron-witness-count 0 \
--protocol-params-file params.json | awk '{ print $1 }')
echo fee: $fee
Calculate your change output.
block producer node
echo Change Output: ${txOut}
Build your transaction.
block producer node
cardano-cli transaction build-raw \
${tx_in} \
--tx-out $(cat payment.addr)+${txOut} \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee ${fee} \
--withdrawal ${withdrawalString} \
--out-file tx.raw
Copy tx.raw to your cold environment.
Sign the transaction with both the payment and stake secret keys.
air-gapped offline machine
cardano-cli transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--signing-key-file stake.skey \
--mainnet \
--out-file tx.signed
Copy tx.signed to your hot environment.
Send the signed transaction.
block producer node
cardano-cli transaction submit \
--tx-file tx.signed \
Check if the funds arrived.
block producer node
cardano-cli query utxo \
--address ${destinationAddress} \
You should see output similar to this showing your updated Lovelace balance with rewards.
TxHash TxIx Lovelace