Submitting a Simple Transaction
Let's walk through an example to send 10 ADA to CoinCashew's tip address 🙃
First, find the tip of the blockchain to set the invalid-hereafter parameter properly.
currentSlot=$(cardano-cli conway query tip --mainnet | jq -r '.slot')
echo Current Slot: $currentSlot
Set the amount to send in lovelaces. ✨ Remember 1 ADA = 1,000,000 lovelaces.
amountToSend=10000000
echo amountToSend: $amountToSend
Set the destination address which is where you're sending funds to.
destinationAddress=addr1qxhazv2dp8yvqwyxxlt7n7ufwhw582uqtcn9llqak736ptfyf8d2zwjceymcq6l5gxht0nx9zwazvtvnn22sl84tgkyq7guw7q
echo destinationAddress: $destinationAddress
Find your balance and UTXOs.
utxo_json=$(cardano-cli conway query utxo --address $(cat payment.addr) --mainnet)
tx_in=""
total_balance=0
txcnt=0
# Use jq to iterate over all UTXOs
while read -r txid; do
hash=$(cut -d'#' -f1 <<< "$txid")
index=$(cut -d'#' -f2 <<< "$txid")
amount=$(jq -r --arg txid "$txid" '.[$txid].value.lovelace' <<< "$utxo_json")
if [[ "$amount" != "null" && "$amount" -gt 0 ]]; then
echo "TxHash: ${hash}#${index}"
echo "ADA: ${amount}"
tx_in="${tx_in} --tx-in ${hash}#${index}"
total_balance=$((total_balance + amount))
txcnt=$((txcnt + 1))
fi
done <<< "$(jq -r 'keys[]' <<< "$utxo_json")"
echo
echo "Total available ADA balance: ${total_balance}"
echo "Number of UTXOs: ${txcnt}"
echo "Final --tx-in string: ${tx_in}"
Run the build-raw transaction command.
cardano-cli conway transaction build-raw \
${tx_in} \
--tx-out $(cat payment.addr)+$(( ${total_balance} - ${amountToSend} )) \
--tx-out ${destinationAddress}+${amountToSend} \
--invalid-hereafter $(( ${currentSlot} + 10000 )) \
--fee 200000 \
--out-file tx.tmp
Calculate the current minimum fee:
fee=$(cardano-cli conway transaction calculate-min-fee \
--tx-body-file tx.tmp \
--tx-in-count ${txcnt} \
--tx-out-count 2 \
--mainnet \
--witness-count 1 \
--byron-witness-count 0 \
--protocol-params-file params.json | awk '{ print $1 }')
echo fee: $fee
Calculate your change output.
txOut=$((${total_balance}-${fee}-${amountToSend}))
echo Change Output: ${txOut}
Build your transaction.
cardano-cli conway transaction build-raw \
${tx_in} \
--tx-out $(cat payment.addr)+${txOut} \
--tx-out ${destinationAddress}+${amountToSend} \
--invalid-hereafter $(( ${currentSlot} + 10000 )) \
--fee ${fee} \
--out-file tx.raw
Copy tx.raw to your cold environment.
Sign the transaction with the payment secret key.
cardano-cli conway transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--mainnet \
--out-file tx.signed
Copy tx.signed to your hot environment.
Send the signed transaction.
cardano-cli conway transaction submit \
--tx-file tx.signed \
--mainnet
Check if the funds arrived.
cardano-cli conway query utxo \
--address ${destinationAddress} \
--mainnet
You should see output similar to this showing the funds you sent.
TxHash TxIx Lovelace
----------------------------------------------------------------------------------------
100322a39d02c2ead.... 0 10000000
Last updated