English
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.
block producer node
1
currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
2
echo Current Slot: $currentSlot
Copied!
Set the amount to send in lovelaces.
✨
Remember 1 ADA = 1,000,000 lovelaces.
block producer node
1
amountToSend=10000000
2
echo amountToSend: $amountToSend
Copied!
Set the destination address which is where you're sending funds to.
block producer node
1
destinationAddress=addr1qxhazv2dp8yvqwyxxlt7n7ufwhw582uqtcn9llqak736ptfyf8d2zwjceymcq6l5gxht0nx9zwazvtvnn22sl84tgkyq7guw7q
2
echo destinationAddress: $destinationAddress
Copied!
Find your balance and UTXOs.
block producer node
1
cardano-cli query utxo \
2
--address $(cat payment.addr) \
3
--mainnet > fullUtxo.out
4
​
5
tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
6
​
7
cat balance.out
8
​
9
tx_in=""
10
total_balance=0
11
while read -r utxo; do
12
in_addr=$(awk '{ print $1 }' <<< "${utxo}")
13
idx=$(awk '{ print $2 }' <<< "${utxo}")
14
utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
15
total_balance=$((${total_balance}+${utxo_balance}))
16
echo TxHash: ${in_addr}#${idx}
17
echo ADA: ${utxo_balance}
18
tx_in="${tx_in} --tx-in ${in_addr}#${idx}"
19
done < balance.out
20
txcnt=$(cat balance.out | wc -l)
21
echo Total ADA balance: ${total_balance}
22
echo Number of UTXOs: ${txcnt}
Copied!
Run the build-raw transaction command.
block producer node
1
cardano-cli transaction build-raw \
2
${tx_in} \
3
--tx-out $(cat payment.addr)+0 \
4
--tx-out ${destinationAddress}+0 \
5
--invalid-hereafter $(( ${currentSlot} + 10000)) \
6
--fee 0 \
7
--out-file tx.tmp
Copied!
Calculate the current minimum fee:
block producer node
1
fee=$(cardano-cli transaction calculate-min-fee \
2
--tx-body-file tx.tmp \
3
--tx-in-count ${txcnt} \
4
--tx-out-count 2 \
5
--mainnet \
6
--witness-count 1 \
7
--byron-witness-count 0 \
8
--protocol-params-file params.json | awk '{ print $1 }')
9
echo fee: $fee
Copied!
Calculate your change output.
block producer node
1
txOut=$((${total_balance}-${fee}-${amountToSend}))
2
echo Change Output: ${txOut}
Copied!
Build your transaction.
block producer node
1
cardano-cli transaction build-raw \
2
${tx_in} \
3
--tx-out $(cat payment.addr)+${txOut} \
4
--tx-out ${destinationAddress}+${amountToSend} \
5
--invalid-hereafter $(( ${currentSlot} + 10000)) \
6
--fee ${fee} \
7
--out-file tx.raw
Copied!
Copy tx.raw to your cold environment.
Sign the transaction with the payment secret key.
air-gapped offline machine
1
cardano-cli transaction sign \
2
--tx-body-file tx.raw \
3
--signing-key-file payment.skey \
4
--mainnet \
5
--out-file tx.signed
Copied!
Copy tx.signed to your hot environment.
Send the signed transaction.
block producer node
1
cardano-cli transaction submit \
2
--tx-file tx.signed \
3
--mainnet
Copied!
Check if the funds arrived.
block producer node
1
cardano-cli query utxo \
2
--address ${destinationAddress} \
3
--mainnet
Copied!
You should see output similar to this showing the funds you sent.
1
TxHash TxIx Lovelace
2
----------------------------------------------------------------------------------------
3
100322a39d02c2ead.... 0 10000000
Copied!
Copy link