Create Simple Transaction
Creating a transaction requires various steps:
- Get the protocol parameters
- Calculate the fee
- Define the time-to-live (TTL) for the transaction
- Build the transaction
- Sign the transaction
- Submit the transaction
#
Get protocol parametersGet the protocol parameters and save them to protocol.json
with:
#
Get the transaction hash and index of the UTXO to spend:#
Draft the transactionCreate a draft for the transaction and save it in tx.draft
note
For --tx-in
we use the following syntax: TxHash#TxIx
where TxHash
is the transaction hash and TxIx
is the index; for --tx-out
we use: TxOut+Lovelace
where TxOut
is the hex encoded address followed by the amount in Lovelace
. For the transaction draft --tx-out, --invalid-hereafter and --fee can be set to zero.
#
Calculate the feeA simple transaction needs one input, a valid UTXO from payment.addr
, and two outputs:
- Output1: The address that receives the transaction.
- Output2: The address that receives the change of the transaction.
Note that to calculate the fee you need to include the draft transaction
#
Calculate the change to send back to payment.addrall amounts must be in Lovelace:
For example, if we send 10 ada from a UTxO containing 20 ada, the change to send back to payment.addr
after paying the fee is: 9.832035 ada
#
Determine the TTL (time to Live) for the transactionTo build the transaction we need to specify the TTL (Time to live), this is the slot height limit for our transaction to be included in a block, if it is not in a block by that slot the transaction will be cancelled. So TTL = slot + N slots. Where N is the amount of slots you want to add to give the transaction a window to be included in a block.
Query the tip of the blockchain:
Look for the value of slotNo
Calculate your TTL, for example: 369200 + 200 slots = 369400
#
Build the transactionWe write the transaction in a file, we will name it tx.raw
.
#
Sign the transactionSign the transaction with the signing key payment.skey and save the signed transaction in tx.signed
#
Submit the transaction#
Check the balancesWe must give it some time to get incorporated into the blockchain, but eventually, we will see the effect:
note
--mainnet
identifies the Cardano mainnet, for testnets use --testnet-magic 1097911063
instead.