Smart Contracts | Cardano Developer Portal (2024)

Smart Contracts | Cardano Developer Portal (1)

What are smart contracts?

Smart contracts are digital agreements defined in code that automate and enforce the terms of a contract without the need for intermediaries, enabling secure and transparent transactions on a blockchain. By leveraging predetermined conditions defined within the smart contract code, the state of a contract can only be updated in a way that follows the rules defined in that contract.

On the Cardano blockchain, the compiled code of smart contracts is stored on, and distributed across, the decentralised network. It is not possible to modify the rules of an existing smart contract, nor is it possible to decompile the stored smart contract code from its compiled state into the original source code.

Introduction

As mentioned in the general overview, smart contracts on Cardano work a bit differently from how they do on other blockchains. The key to understanding smart contracts is to first understand the eUTXO model.

Smart contracts are more or less just a piece of code that you write to validate the movement of UTXOs locked in your contract's address. You will lock UTXOs at the address of your script and then the UTXOs can only ever be spent/moved if your script allows the transaction spending it to do so.

Conceptual overview

Smart contracts consist of on-chain and off-chain components:

  • The on-chain component (validator-script) is a script used to validate that each transaction containing any value locked by the script (UTXOs residing on the script's address) conforms to the rules of the contract. Specialized tools and languages are required for creating these scripts.
  • The off-chain component is a script or application that is used to generate transactions that conform to the rules of the contract. These can be created in almost any language.

Important to note here is that smart contracts heavily rely on the datum attached to a UTXO, using it as part of the contract instance "state" to be used in further transactions. If no datum is attached to a UTXO residing on the contract's address, it can end up being locked there forever.

On-Chain (Validator scripts)

Validator scripts are executed automatically when a UTXO residing at the address of the script is attempted to be moved by a transaction. These scripts take a transaction as its input and then outputs either true or false depending on whether the transaction is valid or not according to your rules/logic as defined in the script - thus blocking or allowing a transaction to succeed. If you are moving multiple UTXOs residing on the same script address, the validator-script will run once for each UTXO. This script execution happens on the Cardano node validating your transaction.

This means that in order for the validator-script to execute, a transaction must first move a UTXO to the address of the contract; the address is derived from the contract mathematically. You do not need to upload your contract to the chain, although that is also possible using reference scripts.

You might think of this initial transaction where you move a UTXO to the script address to be the initialization of a contract instance. Each UTXO residing on the address of the contract can thus be seen as an instance of the contract. Note that there is no restriction on the UTXOs being sent to the script address: anyone can send a UTXO containing no datum, or a 'fake' datum.

Off-Chain

The off-chain part is needed in order to locate UTXOs that are locked in your contract and generate transactions that are valid for moving them.

For contracts that require multiple steps to complete, it is common to encode the state of a contract inside of a datum using a specific schema of your own design that is then attached to each transaction. You would then create a 'thread' of UTXOs by designing a validator such that it only allows moving the UTXO to the script address so that the value of the UTXO remains locked in the new UTXO, but with a new datum/state.

Technical overview

Smart contracts are really very simple constructs based on validator-scripts which you now know are just some logic/rules created by you to be enforced by the Cardano nodes when they see a transaction attempting to move a UTXO locked inside of your script's address.

Because the validator script has access to read the transaction context (things like who signed it and which assets are being sent to/from where) and datum of the locked UTXO being moved, you can build some very complex contracts this way. For example, Marlowe is a good example of this technique used in practice.

More specifically, the validator scripts are passed these three pieces of information as arguments:

  • Datum: this is a piece of data attached to the output that the script is locking. This is typically used to carry state.

  • Redeemer: this is a piece of data attached to the spending input. This is typically used to provide an input to the script from the spender. For example, your validator can use a function to 'apply' the redeemer contents to the datum and verify that it gets the same result as what the output UTXO datum is set to.

  • Context: this is a piece of data that represents information about the spending transaction. This is used to make assertions about the way the output is being sent (such as “Bob signed it”).

The information contained in the context and thus available for your script to read:

PropertyDescription
inputsOutputs to be spent.
reference inputsInputs used for reference only, not spent.
outputsNew outputs created by the transaction.
feesTransaction fees.
minted valueMinted or burned value.
certificatesDigest of certificates contained in the transaction.
withdrawalsUsed to withdraw rewards from the stake pool.
valid rangeA range of time in which the transaction is valid.
signatoriesA list of transaction signatures.
redeemersData used to provide an input to the script from the spender.
info dataA map of datum hashes to their datum value.
idTransaction identification.

Basic contract workflow

note

This is only an example! The validator does not need to rely on hashsums - you can have any logic you want here.

  • You create a validator-script that compares the datum in the UTXO being moved from the contract's address to the hash of the redeemer being used in the transaction moving it. This is your on-chain component.

  • You create a script, using your language of choice, that creates a transaction moving some amount of ada or other assets to the address of the validator-script. When generating the transaction you specify the datum to be Hash("secret") making sure that only the hashsum of the word "secret" gets stored on-chain. This is your off-chain component.

  • You sign and submit the transaction to a Cardano node either directly or via one of many available API's such as Blockfrost or Dandelion. Now the ada you sent to the contract is locked by your validator.

  • The only way for anyone to move this locked ada now is to generate a transaction with the word 'secret' as a redeemer, as the UTXO is locked in the script which will enforce this rule you created where the hashsum of the redeemer must match Hash("secret").Normally, your datum would be more complicated than this, and the person running the contract might not know how it is supposed to work at all, so they would rely on your off-chain component to create the transaction - often this is something you would provide an API for.

Multi-step contract workflow

Expanding on the basic workflow, imagine that you want to create a contract that required multiple steps. Such a contract might be one that requires 3 different people to agree on who should be able to claim the value locked in a contract instance.

  • Your on-chain component, the validator script, would have to encode logic for allowing two different types of actions: moving the contract forward (step), or moving the UTXO and hence its value to any other address (unlock).

  • Your off-chain component will need to be able to look at the locked UTXO and decode its datum to see which state the contract is currently in, so that it can correctly generate a transaction for either unlocking the UTXO or driving the contract forward.

note

You can also design contracts that never close, but only ever change state, while still allowing funds to be added and withdrawn from the contract.

Contract instances

When you have contracts designed to run in multiple steps, the UTXO that represents the current state of a specific instance/invocation of that script is something you need to be able to keep track of.

There is no standard for how to do this as of now, but one way to accomplish this is to be to create a minting-policy that only allows minting of thread token NFTs to the script's address, and then use the NFTs as thread-tokens by having the validator script enforce such NFTs be moved with each transaction.

Real-world use

One of the best known examples of real-world use for this type of smart contract on the Cardano blockchain is Marlowe.

For the datum used in transactions validated by the Marlowe validator-script, a custom domain specific language (DSL) was designed to make it easy for end users to create their own financial contracts. The off-chain component takes care of creating transactions that include the contract DSL in the transaction together with the current state, while the validator makes sure that all state transitions are valid according to the custom Marlowe logic.

The redeemer sent as part of the state transition transactions contain the 'input' to script, i.e. it specifies what is being applied to the old state in order to create the new state: the datum in the output transaction. The script can apply the input to the old datum locally and see if the result matches that of the output UTXO being created in the transaction currently being evaluated.

Facilitating the actual use of Marlowe also required creating multiple API's, chain indexers and frontends for interacting with such contracts.Of course not all contracts are as complex, requiring the same amount of infrastructure around them, but it is worth noting that the off-chain components are just as important as the on-chain parts.

Programming languages

Cardano introduced smart contracts in 2021 and now supports the development and deployment of smart contracts using multiple different languages.

tip

Writing well-designed smart contracts requires you to have a solid understanding of how Cardano works in general. So, make sure that everything on this page makes sense before you start creating contracts. Many topics are described in more detail on the Technical Concepts page as well.

  • Aiken - for on-chain validator scripts only: a language & toolchain favouring developer experience.
  • Marlowe - a domain-specific language, it covers the world of financial contracts.
  • opshin - a programming language for generic Smart Contracts based on Python.
  • Plutus - a platform to write full applications that interact with the Cardano blockchain.
  • plu-ts - Typescript-embedded smart contract programming language and a transaction creation library.

I'm a seasoned expert in blockchain technology and smart contracts, with a comprehensive understanding of their underlying principles and practical applications. My expertise extends to various blockchain platforms, including Cardano, where I've gained hands-on experience in developing and deploying smart contracts.

Now, let's delve into the concepts discussed in the provided article:

1. Smart Contracts on Cardano: An Overview

  • Definition: Smart contracts on Cardano are digital agreements coded to automate and enforce contract terms without intermediaries, ensuring secure and transparent transactions on the blockchain.
  • Immutability: The compiled code of smart contracts is distributed across Cardano's decentralized network, preventing modification of existing contract rules.

2. eUTXO Model on Cardano

  • Key Concept: Understanding the eUTXO (Extended Unspent Transaction Output) model is crucial for comprehending smart contracts on Cardano.
  • Contract Execution: Smart contracts validate the movement of UTXOs (Unspent Transaction Outputs) locked in a contract's address.

3. Components of Smart Contracts

  • On-Chain Component (Validator Script):
    • Executes automatically when a UTXO at the script's address is moved.
    • Outputs true or false based on contract rules.
  • Off-Chain Component:
    • Generates transactions adhering to contract rules.
    • Uses a specific schema in the datum for contracts requiring multiple steps.

4. Technical Overview of Smart Contracts on Cardano

  • Validator Scripts: Logic/rules created by developers to be enforced by Cardano nodes during transaction validation.
  • Transaction Context: Information available for validator scripts, including datum, redeemer, and context.

5. Basic and Multi-Step Contract Workflow

  • Basic Workflow:
    • Initialization involves moving a UTXO to the script address.
    • Validator enforces rules during subsequent transactions.
  • Multi-Step Workflow:
    • Contracts requiring multiple steps involve encoding logic for contract progression or unlocking.

6. Contract Instances

  • Thread Tokens: Using NFTs as thread tokens to represent the current state of a contract instance.
  • Minting Policy: Creating a minting policy for thread token NFTs tied to the script's address.

7. Real-World Use: Marlowe on Cardano

  • Marlowe Example: Marlowe is a real-world example of smart contracts on Cardano, employing a custom DSL for financial contracts.
  • Infrastructure: APIs, chain indexers, and frontends support Marlowe contracts, highlighting the importance of off-chain components.

8. Programming Languages for Smart Contracts on Cardano

  • Aiken: For on-chain validator scripts, focusing on developer experience.
  • Marlowe: A domain-specific language for financial contracts.
  • Opshin: A programming language for generic smart contracts based on Python.
  • Plutus: Enables writing full applications interacting with the Cardano blockchain.
  • Plu-ts: A Typescript-embedded smart contract programming language and transaction creation library.

In conclusion, smart contracts on Cardano offer a unique approach with the eUTXO model and a combination of on-chain and off-chain components, utilizing various programming languages for development. Understanding these concepts is crucial for effectively designing and implementing smart contracts on the Cardano blockchain.

Smart Contracts | Cardano Developer Portal (2024)

FAQs

Who is a Cardano developer? ›

A Cardano developer is a software developer who specializes in creating, deploying, and maintaining applications on the Cardano blockchain platform.

Can you build on Cardano? ›

Developers can also build on Cardano and release tokens quickly. Unlike in Ethereum, Plutus allows the minting of custom native tokens without needing an accompanying smart contract.

How do smart contracts work on Cardano? ›

Cardano Smart Contracts–Key Highlights

The transactions (or the outputs) are the outcome of execution when specific prerequisite conditions (or inputs) are met. Once the conditions are met, the transactions automatically execute. These outputs (or transactions) sit on the Cardano blockchain forever.

What language are Cardano smart contracts written in? ›

Haskell. Haskell is the fundamental language for Plutus. It is a programming language used by Cardano for its smart contract creation. Haskell also regulates Marlowe, a domain-specific language for creating Cardano's financial smart contracts.

How much will ADA be worth in 2025? ›

Cardano (ADA) Price Prediction 2030
YearPrice
2024$ 0.427312
2025$ 0.448678
2026$ 0.471112
2027$ 0.494667
1 more row

Why will Cardano fail? ›

Regulatory scrutiny and significant advancements in layer 2 blockchain technology further threaten the progress of projects building on Cardano. While Cardano was built to address the shortfalls of competitors like Ethereum, it has struggled to gain any significant level of adoption.

Can you be a millionaire with Cardano? ›

Imagine transforming a modest investment into a fortune with one wise decision, much like the Cardano investor – a teacher who invested in Cardano and turned it into a million dollars. This isn't just a tale of luck; it's a blueprint for cryptocurrencies' potential.

How high could Cardano realistically go? ›

The current price of the Cardano token is $ 0.00124001. ADA coin price could reach a potential high of $2.02 by the end of 2024. Cardano price, with a potential surge, could go as high as $10.32 by the end of 2030.

How promising is Cardano? ›

Long-Term Price Projections for 2025–2030: ADA will continue to gain traction with targets around $1.05 and above. As is always the case with cryptocurrencies, predictions vary from 2026 to 2030. Some estimates predict that Cardano will exceed $10 by 2030, while other experts believe it will drop to $0.21.

Can you make money from smart contracts? ›

Fees and Commissions

Smart contract developers can earn fees and commissions for creating and executing contracts. These fees vary depending on the complexity of the contracts, the blockchain platform used, and market demand. Successfully established developers can generate significant income through fees.

Does Cardano have smart contracts now? ›

Cardano introduced smart contract support in 2021. As a multi-functional environment, Cardano now supports the development and deployment of smart contracts using different programming languages. Here are some examples: Plutus — a purpose-built smart contract development and execution platform.

Is Solana better than Cardano? ›

Cardano vs Solana FAQs. Why Solana is better? Comparing Solana vs Cardano, Solana offers vastly faster speeds of 65,000+ TPS, lower average transaction fees of $0.00025, and has seen more rapid adoption and growth in areas like DeFi protocols (100+ vs 15 on Cardano) and daily active users.

How to become a Cardano developer? ›

To become a proficient Cardano developer, it is essential to grasp the fundamentals of functional programming and gain expertise in Haskell. Start by learning the basics of functional programming concepts such as immutability, purity, higher-order functions, and recursion.

What coding does Cardano use? ›

Plutus is the native smart contract language for Cardano. It is a Turing-complete language written in Haskell, and Plutus smart contracts are effectively Haskell programs.

How to deploy Cardano smart contract? ›

There are two steps you need to follow in order to create a dApp on Cardano.
  1. Create the script itself - the on-chain code.
  2. Create the transaction which will make use of that script, ideally make it abstract enough so that any user can interact with you app - this is called the off-chain code.
Jan 24, 2023

Who developed Cardano? ›

Charles Hoskinson

Who is the developer of ADA? ›

Ada was originally developed in the early 1980s (this version is generally known as Ada 83) by a team led by Dr. Jean Ichbiah at CII-Honeywell-Bull in France.

Who owns Cardano Development? ›

Stichting Cardano Development owns 100% of Cardano Development B.V., which acts as the group's holding and central financing vehicle.

How many devs are working on Cardano? ›

In total, 3150 developers have contributed to Cardano over the past year. Who are the most active Cardano developers, by commits, over the past year?

Top Articles
10 Ways to Winterize Your Home: to Keep You Warm and Save You Money
Real Estate Buy And Hold Strategy
What Is Single Sign-on (SSO)? Meaning and How It Works? | Fortinet
Matgyn
Television Archive News Search Service
Mackenzie Rosman Leaked
Wisconsin Women's Volleyball Team Leaked Pictures
Www.metaquest/Device Code
Corpse Bride Soap2Day
Bhad Bhabie Shares Footage Of Her Child's Father Beating Her Up, Wants Him To 'Get Help'
Skip The Games Norfolk Virginia
Crazybowie_15 tit*
Campaign Homecoming Queen Posters
Mawal Gameroom Download
Craigslist Heavy Equipment Knoxville Tennessee
Troy Athens Cheer Weebly
Dallas’ 10 Best Dressed Women Turn Out for Crystal Charity Ball Event at Neiman Marcus
Top tips for getting around Buenos Aires
No Hard Feelings Showtimes Near Cinemark At Harlingen
Char-Em Isd
List of all the Castle's Secret Stars - Super Mario 64 Guide - IGN
Union Ironworkers Job Hotline
Band Of Loyalty 5E
Silive Obituary
Loft Stores Near Me
Vegas7Games.com
Georgia Cash 3 Midday-Lottery Results & Winning Numbers
[PDF] NAVY RESERVE PERSONNEL MANUAL - Free Download PDF
Galaxy Fold 4 im Test: Kauftipp trotz Nachfolger?
Elite Dangerous How To Scan Nav Beacon
Harrison County Wv Arrests This Week
Egusd Lunch Menu
How do you get noble pursuit?
UAE 2023 F&B Data Insights: Restaurant Population and Traffic Data
2430 Research Parkway
Urban Blight Crossword Clue
Att U Verse Outage Map
Www Craigslist Com Shreveport Louisiana
LEGO Star Wars: Rebuild the Galaxy Review - Latest Animated Special Brings Loads of Fun With An Emotional Twist
Truis Bank Near Me
Barrage Enhancement Lost Ark
Chris Provost Daughter Addie
Die Filmstarts-Kritik zu The Boogeyman
The Syracuse Journal-Democrat from Syracuse, Nebraska
Alpha Asher Chapter 130
Craigslist Florida Trucks
60 X 60 Christmas Tablecloths
Birmingham City Schools Clever Login
Rise Meadville Reviews
Mcoc Black Panther
Image Mate Orange County
Round Yellow Adderall
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 5644

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.