Sending ADA, a Simple Transaction Guide

We are going to first create a simple transaction using "cardano-cli transaction build-raw"

First we need to take a look at the UTxO's (Unspent Transaction Outputs) associated with our address in wallet1. These are sort of like bills or coins of a currency.

cardano-cli query utxo --testnet-magic 1 --address $(cat ~/preprodnet/wallets/wallet1/payment.addr)

Let's dissect the output for a second. (Note: there can be many UTxOs owned by a single wallet). First part of the UTxO is the UTxO hash.

This section here is the Tx Hash of the UTxO. We will need to copy the TxHash and TxIx of each UTxO we would like to consume when sending ADA.

Second is the TxIx. This is typically referential to the amount of times a UTxO with this hash has been consumed.

Since we have not consumed or used this UTxO yet, its TxIx is 0.

Lastly is the amount of ADA (test ADA in our case) contained within the UTxO.

Here we see a value in Lovelaces. The faucet generously gave us 10 thousand tADA to use.

Before we begin, create a directory to house the files we create when making transactions.

Now, we are going to query and note the protocol parameters. You will need this for things like calculating the tx fee and stakepool parameters.

Next, we are going to use the "transaction build-raw" command from cardano-cli to build a draft which we will use to calculate our transaction fee.

Notice that we are keeping certain fields at 0 for now. This is because this is just a draft used to calculate the blockchain transaction fee. The fee will potentially increase as we add inputs (consuming more UTxOs) or add more outputs (sending to multiple wallets at a time).

Let's use the tx1.draft to calculate our transaction minimum fee.

Please be aware that your minfee may be different as this number can be a bit dynamic based on a variety of factors.

We need to calculate change, or the total we are sending back to wallet1 from wallet1. With UTxO, the output must equal the input, minus the fee. So we are going to send 100 tADA (100000000 lovelace) to wallet2, pay the fee (174961 in our case, yours may be different), and send the remainder of our UTxO back to wallet1. For us, this looks like 10000000000 (our total UTxO value) minus 174961 (fee), minus 100000000 (the tADA we are sending to wallet2). We get 9899825039. Double check your math as everything needs to match for a successful transaction.

Next we need to assign a validity interval. Time on the blockchain is measured in slots (1 slot per second). When we query the tip of the blockchain we can get the current slot, add an amount of slots that will give us sufficient time to sign and submit our transaction, and then use that number as our --invalid-hereafter option for the transaction.

The number we are interseted is "slot", which sort of gives us a current time on the chain.

Our current "slot" was 18118052. We are going to select a future slot well into the future, in this case we'll lazily round up to 18120000. (Remember, each slot is a second, so you can set a more appropriate window if you'd like).

Now we are ready to build the raw transaction.

Now that we have the raw transaction built, it is time to sign it with our private payment key!

Lastly, it's time to submit the transaction!

If all goes well you have successfully submitted a transaction. Use the cardano-cli query utxo command on each of your wallet addresses to confirm that the tADA have been sent. Please note that this may take a few seconds as the transaction initially gets sent to the mempool waiting to be added into the next block.

You should see both existing and new UTxOs with their associated lovelace balances. Your TxIx#1 of the same TxHash should have 100000000 unlike the images above however.


Congrats! You are ready to move on. But before you do, try this again and create an additional wallet for an additional tx-output.

Last updated