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 the protocol parameters and save them to
Create a draft for the transaction and save it in tx.draft
--tx-in we use the following syntax:
TxHash is the transaction hash and
TxIx is the index; for
--tx-out we use:
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.
A 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
all 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
To 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
Calculate your TTL, for example: 369200 + 200 slots = 369400
We write the transaction in a file, we will name it
Sign the transaction with the signing key payment.skey and save the signed transaction in tx.signed
We must give it some time to get incorporated into the blockchain, but eventually, we will see the effect:
--mainnet identifies the Cardano mainnet, for testnets use
--testnet-magic 1097911063 instead.