Page cover

Creating a simple transaction

You can use cardano-cli to create simple transactions:

cardano-cli transaction

Creating a transaction with build-raw

To create a transaction using build-raw, you will need the protocol parameters. These parameters are necessary for calculating the transaction fee at a later stage:

cardano-cli query protocol-parameters --testnet-magic 2 --out-file pparams.json

You will also need to know the transaction hash and index from which you intend to send funds:

cardano-cli query utxo --address $(cat payment.addr) --testnet-magic 2

Let's send 5,000 ada to the paymentwithstake.addr:

cardano-cli transaction build-raw --babbage-era \
--tx-in $(cardano-cli query utxo --address $(cat payment.addr) --testnet-magic 2 --out-file  /dev/stdout | jq -r 'keys[0]') \
--tx-out $(cat paymentwithstake.addr)+5000000000 \
--tx-out $(cat payment.addr)+5000000000 \
--fee 0 \
--protocol-params-file pparams.json \
--out-file tx.draft
cardano-cli transaction calculate-min-fee --tx-body-file tx.draft \
--testnet-magic 2 \
--protocol-params-file pparams.json \
--tx-in-count 1 \
--tx-out-count 2 \
--witness-count 1 

This information will enable you to determine the transaction fee that needs to be paid, for example:

Now, you need to reconstruct the transaction body by including the fees and recalculating the change that you intend to send to payment.addr

Sign and submit the transaction using the payment.skey generated earlier:

Creating a transaction with build

Now, let's send the rest of the funds from payment.addr to paymentwithstake.addr. This time, you can use the build command, which automatically handles the fees, streamlining the process:

Sign and submit:

Last updated

Was this helpful?