Submitting a Simple Transaction

Let's walk through an example to send 10 ADA to CoinCashew's tip address 🙃

The minimum amount, or smallest UTXO, you can send in one transaction is 1 ADA.

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

Retrieve the UTXOs available for your payment address and calculate the balance.

# Retrieve the list of UTXOs available for your payment address
utxo_json=$(cardano-cli conway query utxo --address $(cat payment.addr) --mainnet)

# Initialize variables
tx_in=""
total_balance=0
txcnt=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 "ADA: ${utxo_balance}"
        tx_in="${tx_in} --tx-in ${hash}#${idx}"
		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.

Calculate the current minimum fee:

Calculate your change output.

Build your transaction.

Copy tx.raw to your cold environment.

Sign the transaction with the payment secret key.

Copy tx.signed to your hot environment.

Send the signed transaction.

Check if the funds arrived.

You should see output similar to this showing the funds you sent.

Last updated