Cardano Building Blocks

Cardano's building blocks include nodes, which are responsible for validating transactions, propagating blocks, and participating in the consensus process; stake pools, which allow smaller stakeholders to participate in the consensus process by pooling their resources together and collectively staking their ADA tokens; and Ouroboros, Cardano's proof-of-stake consensus algorithm that ensures the security and scalability of the blockchain network. These components work together to enable decentralization, transparency, and security in the Cardano ecosystem, allowing users to contribute to the growth of the network and earn rewards for their contributions.

Table of Content

Nodes

A node refers to a computer that is running the Cardano software and participating in the network. Nodes are essential for maintaining the integrity and security of the blockchain, as they are responsible for validating transactions, propagating blocks, and participating in the consensus process.

There are three types of Cardano nodes:

  • Relay Nodes: These nodes are responsible for propagating transactions and blocks throughout the network. Relay nodes receive transactions and blocks from other nodes, verify them, and then propagate them to other nodes in the network. Relay nodes do not participate in the consensus process.
  • Core Nodes: These nodes are responsible for participating in the consensus process and generating new blocks. Core nodes receive transactions from relay nodes, validate them, and then include them in new blocks. Core nodes also communicate with other core nodes in the network to ensure that they all agree on the current state of the blockchain.
  • Edge Nodes: These nodes are used by end-users to interact with the Cardano blockchain. Edge nodes can be run by anyone and can be used to submit transactions, query the blockchain, and interact with decentralized applications.

Running a Cardano node requires a certain level of technical expertise, as it involves setting up and configuring the necessary software, managing the node's resources, and monitoring its performance. However, running a node can also provide benefits such as increased security, control over one's transactions, and the ability to contribute to the Cardano ecosystem.

Overall, Cardano nodes play a critical role in ensuring the security, integrity, and scalability of the blockchain network. By running a node, users can help contribute to the decentralization and overall health of the Cardano ecosystem.

Producing a block

The goal of blockchain technology is the production of an independently-verifiable and cryptographically-linked chain of records (blocks). A network of block producers works to collectively advance the blockchain. A consensus protocol provides transparency and decides which candidate blocks should be used to extend the chain.

Submitted valid transactions might be included in any new block. A block is cryptographically signed by its producer and linked to the previous block in the chain. This makes it impossible to delete transactions from a block, alter the order of the blocks, remove a block from the chain (if it already has a number of other blocks following it), or to insert a new block into the chain without alerting all the network participants. This ensures the integrity and transparency of the blockchain expansion.

Slots and epochs

Ouroboros divides time into epochs. Each Cardano epoch consists of a number of slots, where each slot lasts for one second. A Cardano epoch currently includes 432,000 slots (5 days). In any slot, zero or more block-producing nodes might be nominated to be the slot leader. On average, one node is expected to be nominated every 20 seconds, for a total of 21,600 nominations per epoch.

Stake Pools

A stake pool refers to a group of users who combine their stake (i.e., ADA tokens) to increase their chances of being selected as a block producer and earning rewards for their contributions to the network.

The Cardano blockchain uses a proof-of-stake (PoS) consensus algorithm, meaning block producers (i.e., validators) are selected based on the amount of stake they hold. Stake pools allow smaller stakeholders to participate in the consensus process by pooling their resources together and collectively staking their ADA tokens.

Here's how it works:

  • Stakeholders delegate their ADA tokens to a stake pool of their choice. Delegating tokens means the pool will use the stake to participate in the consensus process and generate new blocks.
  • The stake pool participates in the consensus process and is periodically selected to produce a block. When a block is produced, the rewards are distributed to the pool's members proportionally to their stake in the pool.
  • The rewards earned by the pool are divided among the members of the pool based on their stake. The pool operator usually takes a small fee (typically 1-5%) to cover the costs of running the pool.

Running a stake pool requires technical expertise and resources, including a dedicated server, reliable internet connection, and secure infrastructure. However, running a stake pool can be profitable for those committed to maintaining the pool's uptime and contributing to the Cardano network.

Stake pools play a critical role in the decentralization of the Cardano blockchain, as they allow smaller stakeholders to participate in the consensus process and earn rewards for their contributions. By delegating their stake to a stake pool, users can help support the network and contribute to the growth of the Cardano ecosystem.

Relay nodes of Stake pools by region. Source: https://cexplorer.io/relays

Slot leader election

Slot leaders are randomly elected from among the stake pools. The more stake a pool controls, the greater the chance it has of being elected as a slot leader to produce a new block that is accepted into the blockchain. This is the basic concept of proof of stake (PoS). To maintain a level playing field, and prevent a situation where a small number of very large pools control the majority of stake, Cardano has an incentive system that discourages delegation to pools that already control a large portion of the total stake.

Delegation

Owning ada not only allows you to buy goods or services, but also confers upon you the right and obligation to participate in the protocol and create blocks. Stake delegation is a mechanism inherent in the Ouroboros protocol that allows the protocol to scale even in a setting where the set of stakeholders might be highly fragmented.

Anyone who owns ada can participate in stake delegation while retaining their spending power. Note that you can spend your ada normally at any time, regardless of how you delegated it. This mechanism will enable stakeholders to participate in the slot leader election process in each epoch.

Stake delegation gives rise to stake pools that act in the similar way to mining pools in the Bitcoin protocol. Stake pool operators (SPOs) must be online to generate blocks if they are selected as slot leaders.

UTXOs

The extended Unspent Transaction Output model (eUTXO) is a key feature of the Cardano blockchain that helps improve the network's security and scalability. The eUTXO model is an extension of the standard UTXO model used in many other blockchains like Bitcoin.

In the eUTXO model, each transaction output is associated with a specific script that defines the conditions that must be met for the output to be spent in a subsequent transaction. These scripts can include complex conditions, such as multi-signature requirements, time locks, and other types of logic that can be used to enforce security and prevent fraud.

When a new transaction is submitted to the Cardano network, the eUTXO model checks the validity of the transaction by verifying that:

  • The inputs to the transaction are valid (i.e., they have not already been spent in a previous transaction).
  • The script associated with each output is satisfied (i.e., the conditions for spending the output have been met).

If the transaction is valid, it is added to the Cardano blockchain as a new block, and the outputs that were spent in the transaction are marked as spent and cannot be used again in future transactions.

One of the main benefits of the eUTXO model is that it allows for greater flexibility and security in the execution of smart contracts. By allowing developers to define complex conditions for spending transaction outputs, the eUTXO model can be used to create a wide range of decentralized applications, including financial instruments, identity management systems, and other types of contracts.

Another benefit of the eUTXO model is that it can help improve the Cardano network's scalability. By breaking transactions into discrete inputs and outputs, the eUTXO model can help reduce the transactions' size and improve the blockchain network's efficiency.

Overall, the eUTXO model is a key innovation in the design of the Cardano blockchain. By enabling greater flexibility and security in the execution of smart contracts, and by improving the scalability of the network, the eUTXO model helps to support the development of a more robust and sustainable blockchain ecosystem.

Smart Contracts

In the Cardano blockchain, smart contracts are implemented using the Plutus programming language, which is based on the Haskell functional programming language. Plutus is a high-level language that allows developers to define complex smart contracts that can be executed on the Cardano blockchain.

Smart contracts in Cardano work by using the extended Unspent Transaction Output (eUTXO) model, which allows developers to define the conditions that must be met in order for funds to be spent from a specific output. These conditions can be based on a wide range of factors, such as time limits, multi-party approval, or other types of logic.

Since its launch, several alternative programming languages have been added to Cardano to improve the developer experience:

Plutus

Plutus is a programming language that is specifically designed for writing smart contracts on the Cardano blockchain. It is a high-level, functional programming language that is based on Haskell, a well-established programming language known for its security, reliability, and mathematical rigour.

Plutus provides a framework for developers to create smart contracts that can be executed on the Cardano blockchain. It allows developers to write contracts using a functional programming paradigm, which makes it easier to reason about the behavior of the code and to ensure that it is correct and secure.

One of the key features of Plutus is its use of the extended Unspent Transaction Output (eUTXO) model, which is a unique feature of the Cardano blockchain. The eUTXO model allows developers to define the conditions that must be met in order for funds to be spent from a specific output. This enables developers to create complex and sophisticated smart contracts that can be executed on the Cardano blockchain.

In addition to providing a programming language for smart contracts, Plutus also includes a number of development tools and libraries that make it easier for developers to build and test their smart contracts. These tools include a simulator for testing smart contracts in a sandbox environment, a code editor with syntax highlighting and autocompletion, and a comprehensive set of documentation and tutorials.

Overall, Plutus is a key component of the Cardano blockchain ecosystem, providing a powerful and flexible programming language for creating smart contracts that can be executed securely and transparently on the blockchain.

Plutus | Cardano Developer Portal
Plutus

Aiken

Aiken is a new programming language and toolchain for developing smart contracts on the Cardano blockchain. It takes inspiration from many modern languages such as Gleam, Rust, and Elm which are known for friendly error messages and an overall excellent developer experience. The language is exclusively used for creating the on-chain validator-scripts.

Aiken | A modern smart contract platform for Cardano
A modern smart contract platform for Cardano

Marlowe

Marlowe is a domain-specific language (DSL) that is specifically designed for creating financial contracts on the Cardano blockchain. It is a high-level programming language that allows non-technical users, such as financial engineers and legal experts, to create financial contracts using a simple and intuitive interface.

Marlowe is built on top of the Plutus programming language, which is used to create more complex smart contracts on the Cardano blockchain. It provides a simpler and more accessible alternative to Plutus for creating financial contracts, with a focus on clarity, simplicity, and ease of use.

One of the key features of Marlowe is its visual contract editor, which allows users to create and edit contracts using a drag-and-drop interface. This makes it easy for non-technical users to create and modify contracts without having to learn a programming language or write code.

Marlowe also includes a number of predefined contract templates, such as options, swaps, and escrows, which users can customize and adapt to their specific needs. These templates provide a starting point for creating contracts, allowing users to focus on the specific terms and conditions of the contract rather than the technical details of the programming language.

Overall, Marlowe is a powerful tool for creating financial contracts on the Cardano blockchain, enabling non-technical users to participate in the creation of smart contracts and supporting the development of a more robust and sustainable blockchain ecosystem

Marlowe: Financial smart contracts on Cardano blockchain
Marlowe: create, test and run financial agreements. Peer-to-peer, secure and scalable DeFi solution. Marlowe makes finance accessible to all.

plu-ts

plu-ts is a Typescript-embedded programming language and library for developing smart contracts on the Cardano blockchain. It is designed for smart contract efficiency while staying as close as possible to the Typescript syntax.

The tool is composed by the eDSL that allows you to create smart contracts and compile them; and an off-chain library that introuduces all the types required to interact with the Cardano ledger and create transactions.

GitHub - HarmonicLabs/plu-ts: An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript - GitHub - HarmonicLabs/plu-ts: An embedded DSL for Cardano smart contracts c...

opshin

opshin is a programming language for developing smart contracts on the Cardano blockchain. Its syntax is 100% valid Python code and it ensures that contracts evaluate on-chain exactly as their Python counterpart. This allows unit tests and verification of the Python code using standard tooling available for Python development. Existing IDEs, linters and language servers may be re-used as well. Note that the type system of opshin is much stricter than the type system of Python, so that many optimizations can be implemented and an elevated level of security is provided.

The language interacts closely with the python library PyCardano. The internal data structures are defined with data types compatible to the library and allow a tight combination of off- and on-chain code, all written in Python.

GitHub - OpShin/opshin: A simple pythonic programming language for Smart Contracts on Cardano
A simple pythonic programming language for Smart Contracts on Cardano - GitHub - OpShin/opshin: A simple pythonic programming language for Smart Contracts on Cardano

On-Chain & Off-Chain

On-chain code refers to the code that is executed directly on the blockchain, while off-chain code refers to code that is executed outside of the blockchain.

On-chain code is executed by nodes in the Cardano network as part of the consensus protocol, and is responsible for validating transactions, executing smart contracts, and updating the state of the blockchain. On-chain code is written in programming languages that are specifically designed for blockchain development, such as Plutus.

Off-chain code, on the other hand, is executed outside of the Cardano blockchain, and is typically used to interact with on-chain code or to perform actions that do not require consensus from the network. Examples of off-chain code include wallets, APIs, and other user interfaces that interact with the blockchain. Off-chain code can be written in a wide range of programming languages, depending on the specific requirements of the application. A good example is the "cardano-serialization-lib" which lets a developer build transactions using javascript

The main difference between on-chain and off-chain code is that on-chain code is executed directly on the blockchain and is subject to the consensus protocol, while off-chain code is executed outside of the blockchain and is not subject to the same constraints. This means that on-chain code is more secure and reliable, as it is protected by the consensus protocol, while off-chain code is more flexible and can be used to build a wider range of applications.

In general, the distinction between on-chain and off-chain code is important for understanding the architecture of the Cardano blockchain, and for developing applications that interact with the blockchain in a secure and efficient way. By using a combination of on-chain and off-chain code, developers can create powerful and flexible applications that leverage the unique features of the Cardano blockchain.

References

Why Cardano chose Haskell

Cardano Documentation

Cardano Developers Portal - Getting Started

Aiken simplifies writing smart contracts for Cardano

Cardano Smart Contracts

Cardano-serialization-lib

Cardano Relay Nodes Geo Distribution

License

This work is distributed under a Creative Commons Attribution 4.0 International (CC BY 4.0) The license allows you to copy and redistribute the material in any medium or format, as well as remix, transform, and build upon the material for any purpose, including commercial, as long as you give appropriate credit to the creator.

Read more