Skip to main content

Claiming Stake Pool Rewards

In the Cardano ecosystem, stake addresses store rewards that you earn for staking. Staking rewards and any new ADA in a wallet are automatically included in the staking balance for the account. You do not need to claim staking rewards. However, you may claim rewards that you earn for operating or delegating to a stake pool at any time.

Note
Note

Cardano CLI commands throughout the How to Set Up a Cardano Stake Pool guide may use the ‑‑mainnet option. If you are working in a Testnet environment, then remember to replace each instance of the ‑‑mainnet option with ‑‑testnet‑magic <MagicNumber> where <MagicNumber> is the network magic number for the Testnet that you use.

To claim rewards that the stake pool you operate earns:

  1. Ensure that the stake address storing rewards to claim is Delegating to a Representative.
  2. Ensure that the destination payment address receiving staking rewards has a balance of at least ₳1 to pay the transaction fee.

    Note
    Note

    The transaction fee for claiming rewards is about 200,000 Lovelace.

  3. On the block-producing node in your stake pool configuration, using a terminal window type the following commands to save protocol parameters:
    cd $NODE_HOME
    cardano-cli conway query protocol-parameters \
    --mainnet \
    --out-file params.json
  4. When the local copy of the Cardano blockchain ledger is fully synchronized, type the following command using a terminal window to query the slot number of the current tip of the ledger:
    currentSlot=$(cardano-cli conway query tip --mainnet | jq -r '.slot')
    echo "Current Slot: ${currentSlot}"
  5. To assign the amount of rewards to claim to a variable, type:
    rewardBalance=$(cardano-cli conway query stake-address-info \
    --address $(cat $NODE_HOME/stake.addr) \
    --mainnet | jq -r ".[0].rewardAccountBalance")
    echo Reward Balance: ${rewardBalance}

    Note
    Note

    You must claim the full amount of staking rewards available. You cannot claim partial staking rewards.

  6. To assign the stake address and amount of rewards available to a variable using a format that the transaction requires, type:
    withdrawalString="$(cat $NODE_HOME/stake.addr)+${rewardBalance}"
    echo Withdrawal String: ${withdrawalString}
  7. To retrieve the UTXOs available for the destination payment address and calculate the balance, type:
    # Retrieve the list of UTXOs available for your payment address
    utxo_json=$(cardano-cli conway query utxo \
    --address $(cat $NODE_HOME/payment.addr) \
    --mainnet)

    # Initialize variables
    tx_in=""
    total_balance=0

    # Loop through the list of UTXOs
    while read -r utxo; do
    # Retrieve the values for the current UTXO
    values=$(jq -r --arg k "${utxo}" '.[$k]' <<< "${utxo_json}")
    # Retrieve datum associated with the UTXO
    datum=$(jq -r '.datum' <<< "${values}")
    # Retrieve the reference script associated with the UTXO
    script=$(jq -r '.referenceScript' <<< "${values}")
    # If limits on spending the UTXO may exist, then skip the UTXO
    if [[ ${datum} == 'null' && ${script} == 'null' ]]
    then
    hash=${utxo%%#*}
    idx=${utxo#*#}
    utxo_balance=$(jq -r '.value.lovelace' <<< "${values}")
    total_balance=$((${total_balance}+${utxo_balance}))
    echo "TxHash: ${hash}#${idx}"
    echo "UTXO Balance: ${utxo_balance} Lovelace"
    tx_in="${tx_in} --tx-in ${hash}#${idx}"
    fi
    done <<< "$(jq -r 'keys[]' <<< "${utxo_json}")"

    echo
    echo "Total available balance: ${total_balance} Lovelace"
    echo "Final --tx-in string:${tx_in}"
  8. To build a draft transaction for calculating the transaction fee, type:
    cardano-cli conway transaction build-raw \
    ${tx_in} \
    --tx-out $(cat $NODE_HOME/payment.addr)+$(( ${total_balance} - 200000 + ${rewardBalance} )) \
    --invalid-hereafter $(( ${currentSlot} + 10000 )) \
    --fee 200000 \
    --withdrawal ${withdrawalString} \
    --out-file $NODE_HOME/tx.tmp
  9. To calculate the fee for the transaction, type:
    fee=$(cardano-cli conway transaction calculate-min-fee \
    --tx-body-file $NODE_HOME/tx.tmp \
    --witness-count 2 \
    --byron-witness-count 0 \
    --protocol-params-file $NODE_HOME/params.json | jq -r '.fee')
    echo "Fee: ${fee}"
  10. To calculate change from the transaction, type:
    txOut=$(( ${total_balance} - ${fee} + ${rewardBalance} ))
    echo Change: ${txOut}
  11. To build the transaction, type:
    cardano-cli conway transaction build-raw \
    ${tx_in} \
    --tx-out $(cat $NODE_HOME/payment.addr)+${txOut} \
    --invalid-hereafter $(( ${currentSlot} + 10000 )) \
    --fee ${fee} \
    --withdrawal ${withdrawalString} \
    --out-file $NODE_HOME/tx.raw
  12. Copy the tx.raw file that you created in step 11 to the $NODE_HOME folder on your air-gapped, offline computer, and then using a terminal window type the following commands to sign the transaction:
    cd $NODE_HOME
    cardano-cli conway transaction sign \
    --tx-body-file tx.raw \
    --signing-key-file payment.skey \
    --signing-key-file stake.skey \
    --mainnet \
    --out-file tx.signed
  13. Copy the tx.signed file that you created in step 12 to the $NODE_HOME folder on the block-producing node, and then using a terminal window type the following command to submit the transaction to the network:
    cardano-cli conway transaction submit \
    --tx-file $NODE_HOME/tx.signed \
    --mainnet
  14. To verify that staking rewards are claimed successfully, type the following command to display the list of Unspent Transaction Output (UTXOs) available for the payment address receiving staking rewards in the transaction, and then find the UTXO that the transaction output:
    cardano-cli conway query utxo \
    --address $(cat $NODE_HOME/payment.addr) \
    --mainnet