Technical Guide to Building Transactions on Cardano
Author: Adaverse
To fully understand how Cardano works, it's essential to grasp several concepts --- the Cardano mechanism is very similar to Bitcoin, with some additional features extended:
- UTXOs
- Native Assets (Tokens and NFTs)
- Smart Contracts
In short, Cardano adopts the Bitcoin UTXO model and expands upon it, with only two truly important features, native assets and smart contracts.
UTXOs
The most important concept to understand in Cardano may be the UTXO model --- the UTXO model was initially used for Bitcoin, but it has many limitations in smart contract development. Ethereum abandoned this model to implement smart contracts, opting for an account model (most public chains that support smart contracts do the same).
Cardano inherits the advantages of Bitcoin at the consensus layer, while considering the needs of smart contract implementation in state selection. It draws on Ethereum's design ideas and uses a modified version of UTXO (EUTXO) to support smart contracts.
The Cardano documentation includes a series of video tutorials that explain many concepts at a higher level, including how each transaction is executed and how UTXO works.
The first two videos about UTXO and transactions are very important concepts that need to be understood, as they help us understand how assets are stored in Cardano and the information stored in each transaction.
After grasping the high-level concepts of UTXO and transactions, the best practice is to actually build and submit a transaction, which can be broken down into three steps:
- Build a transaction;
- Sign the transaction with a private key;
- Submit the transaction to a Cardano node;
Cardano-cli
The first method for building, signing, and submitting transactions is using "Cardano-cli." This method is very user-friendly and almost guarantees the success of the transaction, but it requires the user to set up a Cardano node.
For many ordinary users, this is undoubtedly a significant barrier --- it requires quite powerful hardware and a lot of spare memory.
However, the Cardano documentation also has a guide on how to run a node and CLI.
If a node has already been set up, here is a guide for a very simple transaction you can try.
Cardano-serialization-lib + a Light Wallet
The second method for building and submitting transactions is to use Cardano-serialization-lib in combination with a light wallet.
Although users can use any light wallet they want, I created a project as an example to demonstrate how to use Cardano-serialization-lib and the Yoroi wallet to build, sign, and submit transactions to the testnet.
It mainly demonstrates how to generate an NFT and send it to a script address:
- First, install Yoroi Nightly (the development version of the Yoroi wallet, which supports the testnet).
- Then, obtain some testnet ADA from the faucet;
- Then you can clone this Github repository and run npm as a developer (the default service location is http://localhost:8080/).
Tokens and NFTs
Once you understand how basic transactions work, it's necessary to further explore how tokens and NFTs operate on Cardano.
The Cardano documentation has a lengthy introductory article that explains that tokens and NFTs on Cardano are referred to as "native assets" because Cardano supports custom tokens and NFTs at the blockchain layer, while Ethereum uses smart contracts to represent these assets.
Tokens and NFTs are treated the same way as ADA on Cardano, essentially each asset has a unique ID, while ADA uses an empty string as its unique ID.
There are two important concepts to understand regarding tokens and NFTs:
- Minting Strategy
- Metadata
The ID of a token is actually just the hash of its minting strategy, and the minting strategy is a set of instructions that indicate whether it can be minted.
The metadata of a token is where other important information about the token is stored. Currently, CIP25 provides a standard to standardize the format of token metadata.
Minting Tokens
Using CLI, using serialization-lib + light wallet,
Plutus Scripts (Smart Contracts)
To truly understand Cardano, the final challenge is to comprehend its smart contract system.
However, there is no simple way to learn this part; it requires a significant time investment. There is no better way to learn than to follow the series of videos released by IOG --- the "Plutus Pioneer Program."
This video series will guide us on how to create Plutus scripts, test and deploy them, and provide us with many good examples of scripts that can be built on Cardano.
If you want to learn more about Cardano's technical aspects, you can contact Adaverse.