How are Cardano Blockchain Transactions Completed

Introduction

You might already know that the Cardano blockchain can be used to transfer ADA or other native tokens, mint or burn tokens, execute smart contracts etc. in the process of the transaction. So in common terms, a transaction is an exchange of value among some parties and optionally executes programmed logic called smart contracts. With this picture in the backdrop, let us go a level deeper to break down how transactions are completed on the Cardano Blockchain.

 

How can we define a transaction?

A transaction is an operation that modifies the state of the ledger on the blockchain. Sending or minting tokens, delegating to stake pool, running a smart contract etc all affect the ledger state. 

 

Submitting transactions 

Transactions can be submitted to the blockchain by various means like a Cardano wallet, a dApp frontend or backend and other tools like the cardano-cli. A transaction before submission is prepared in its prescribed format. It will contain details representing input and output utxos, fees involved, the scripts involved, if any, for the transaction. In case the transaction involves execution of Plutus scripts the necessary collateral will also have to be set. More about why collateral is required will be explained later.

 

The transaction is first prepared as an unsigned transaction and then before submitting to the blockchain the transaction body is appended with a signature that signifies that the utxos or policies used in the transaction can be used by whoever is creating the transactions. 

 

How are tx processed by the network?

Once the transaction is signed it gets submitted to a cardano-node which is running locally or on a remote server. The transaction received by the cardano-node is added into the mempool. A mempool is a collection of transactions which are yet to be processed by the blockchain. The transaction is picked from the mempool and validated before it gets added to a block. A node that has been selected for block creation for the corresponding block does this. Other nodes that communicate with this node get the block that contains this transaction and likewise it gets propagated across the network. When the block containing this transaction is accepted by the network the transaction is completed.

 

Once a transaction is processed by the network you can track it using any of the blockchain explorers. Commonly used tools for exploring the transactions and block details on Cardano are https://explorer.cardano.org/en.html and https://cardanoscan.io/. You will find other tools out there as well as is usual in the Cardano community.

 

More about validation of a transaction

Validation of a transaction essentially is a check by the node that the actions performed by the transaction are permitted. A simple example of validity check is whether the inputs (read as ADA) being spent in the transaction is owned by the spender and the tx is signed by that owner. Cardano is also smart contract enabled since the Alonzo era via the use of Plutus scripts. As a result this validation step can also include logic written in smart contracts that tells whether the action is permitted. This form of script validation occurs in the case of spending a UTXO locked by a script address, minting a token, withdrawing staking rewards or applying certificates.

 

If a transaction includes Plutus scripts, it might require significantly more resources to validate. In such a scenario it is possible that nodes expend resources for  validating scripts of transactions but it gets rejected for some reason. In order to optimize the resource usage Alonzo introduced a two-phase validation approach which limits the amount of uncompensated validation work done by nodes. The first phase checks whether the transaction is constructed correctly and can pay its processing fee. The second phase runs the scripts included in the transaction. The phase-2 is executed only in case phase-1 passes. If the phase-1 validation fails the node has done just a small amount of uncompensated work and the user does not lose any fee. If phase-1 passes then a successful execution phase-2 transaction rewards the node with the transaction fee. In case the phase-2 transaction fails the collateral set for the transaction is collected.