Skip to main content

Withdrawing transactions

This part of the tutorial will demonstrate how easy it is to claim rewards using the cardano-cli. First, you need to ensure that you already have rewards available in your stake address. Check it with the following command:

$ cardano-cli query stake-address-info --address $(cat stake.addr)
[
{
"address": "stake_test1uq954t492tmusk2dy9z505g3cz3sfpnh0swsqjmzk47rasqyn8uqp",
"delegation": "pool18pn6p9ef58u4ga3wagp44qhzm8f6zncl57g6qgh0pk3yytwz54h",
"rewardAccountBalance": 29385845
}
]

In this case, you have ~29 ada. You also need some of your own ada to pay the fees, so you need to query your payment address:

$ cardano-cli query utxo --address $(cat payment.addr)
TxHash TxIx Amount
--------------------------------------------------------------------------------------
afb33e353a9880b7cbd9e5eb2cbffa024d1b3b938ee2c739e53dd187094e8f0d 0 10000000 lovelace + TxOutDatumInline ReferenceTxInsScriptsInlineDatumsInBabbageEra (HashableScriptData "\216y\159\CAN*\255" (ScriptDataConstructor 0 [ScriptDataNumber 42]))
afb33e353a9880b7cbd9e5eb2cbffa024d1b3b938ee2c739e53dd187094e8f0d 1 9987657206 lovelace + TxOutDatumNone

Use the second UTXO with TxIx=1. You're ready to create your withdrawal transaction:

cardano-cli transaction build \
--tx-in afb33e353a9880b7cbd9e5eb2cbffa024d1b3b938ee2c739e53dd187094e8f0d#1 \
--withdrawal $(cat stake.addr)+29385845 \
--change-address $(cat payment.addr) \
--out-file withdrawal-tx.raw

Note that this transaction will take funds from the stake address, so it will need to be signed with the stake.skey file:

cardano-cli transaction sign \
--tx-file withdrawal-tx.raw \
--signing-key-file payment.skey \
--signing-key-file stake.skey \
--out-file withdrawal-tx.signed

cardano-cli transaction submit --tx-file withdrawal-tx.signed

Finally, verify that you have received your rewards in your payment address:

$ cardano-cli query utxo --address $(cat payment.addr)
TxHash TxIx Amount
--------------------------------------------------------------------------------------
2b1bfc342c1f5531df4cfa220eac79574142c7263d97885d2ad8588ca1a7e22b 0 10016871698 lovelace + TxOutDatumNone
afb33e353a9880b7cbd9e5eb2cbffa024d1b3b938ee2c739e53dd187094e8f0d 0 10000000 lovelace + TxOutDatumInline ReferenceTxInsScriptsInlineDatumsInBabbageEra (HashableScriptData "\216y\159\CAN*\255" (ScriptDataConstructor 0 [ScriptDataNumber 42]))