Book a free call

How to Create a Smart Contract on Cardano

Cardano smart contracts are validator scripts that approve or reject transactions under the eUTXO model. Learn the languages, tools and steps to build one.

Hertiv engineering teamReviewed by a senior engineer
6 min read
How to Create a Smart Contract on Cardano
On this page

Short answer

A Cardano smart contract is a validator script, written in Aiken, Plutus or Marlowe, that guards funds locked at a script address and approves or rejects any transaction that tries to spend them. You write the on-chain validator, test it against mock transactions, then build the off-chain code that finds locked funds and submits transactions the validator accepts.

What is a Cardano smart contract?

A Cardano smart contract is a validator script: code that guards funds locked at a script address and approves or rejects any transaction that tries to spend them. The script does not move money by itself. It only answers yes or no when a transaction is proposed.

Cardano uses the extended unspent transaction output model, known as eUTXO. Every coin sits in an unspent output with a value and, optionally, a piece of data called a datum. When you send funds to a script address, the validator attached to that address decides whether a later transaction may spend them.

A validator reads three inputs: the datum stored with the locked funds, the redeemer supplied by the spender to name the action, and the context, which is the full transaction under review. All three must satisfy the script’s rules before the spend is approved.

This design is different from account-based chains, where a contract can hold a balance and call other contracts directly. Guides for other chains, such as creating a contract on Solana, follow a different model.

How does a Cardano smart contract work?

A Cardano smart contract works in two halves. The on-chain half is the validator, which runs on every node and checks the datum, redeemer and context of a proposed spend. The off-chain half is the application that finds locked funds, builds the transaction and submits it.

The validator cannot take actions of its own. It cannot send tokens, call another contract, fetch data from the internet or generate random numbers. It only approves or rejects the transaction in front of it. That limit keeps execution predictable: a transaction’s outcome depends only on the transaction itself and its inputs, never on other activity on the chain.

Every script runs inside an execution budget, so it must finish and cannot loop forever. The budget also caps the cost of running the script, which is part of the transaction fee. Because the validator is pure logic, you can test it with mock transactions before any real funds are involved, which is how most teams catch mistakes early.

Which language should you write it in?

You can write a Cardano validator in several languages, and all of them compile to the same on-chain bytecode, called UPLC. The choice changes how comfortable the work is, not what the contract can do. Most new projects start with Aiken, while teams with Haskell experience often stay with Plinth.

LanguageBest forWhat to know
AikenNew projectsBuilt for validators, fast builds, built-in tests
Plinth (Plutus Tx)Haskell teamsShares types with off-chain code, steeper learning curve
MarloweFinancial agreementsLimited by design, every contract ends, visual Playground
OpShinPython teamsPython-style code compiled to UPLC

Marlowe deserves a note for financial contracts. It is a small language for agreements such as escrows and loans, and its Playground lets you simulate a contract before you deploy it. If your contract is a payment schedule with dates and conditions, Marlowe may be simpler than writing a general validator, and the same care applies to smart contracts for financial agreements on any chain.

What tools do you need before you start?

Before you write a validator, set up the toolchain. Install the Aiken command-line tools with its version manager, aikup, and a Cardano node or a connection to one through a provider. You also need a wallet and test ADA from the testnet faucet, because all first runs should happen on the testnet, never on the main network.

  • Aiken toolchain. Writes, builds and tests validators.
  • Cardano node or API provider. Submits transactions and reads chain state.
  • Testnet wallet and faucet. Funds for testing without real money.
  • Off-chain library. Mesh or Lucid Evolution in TypeScript builds transactions and connects wallets.

The off-chain half matters as much as the validator. It is the code that finds locked funds, assembles the transaction with the right datum and redeemer, and handles the wallet connection. You can write it in any language, and most teams use TypeScript with Mesh or Lucid Evolution. If you need help, a smart contract development partner can review the design before you build.

How do you create a smart contract on Cardano?

Creating a smart contract on Cardano follows a fixed sequence. Each step is small, and you should not move to the next one until the current one passes its checks.

  1. Pick a language, usually Aiken, and set up the project.
  2. Define the datum and redeemer: what data sits with the funds, and which actions spenders may request.
  3. Write the validator so it approves only the transactions you intend.
  4. Test with mock transactions, including the cases that must fail.
  5. Build the off-chain code that locks funds and submits spends.
  6. Deploy to the testnet, lock test funds, and spend them to confirm the rules work.
  7. Get an independent audit before mainnet, and fix every finding.

The audit step is not optional for contracts that will hold other people’s funds. Validators are hard to change once deployed, because the script address is derived from the script itself. A new version means a new address and moving the funds, so catching problems before launch is far cheaper than after. An audit checklist helps you prepare for that review.

Example (hypothetical): a simple escrow contract

Example (hypothetical): a client hires a freelancer for a design job and both agree to use an escrow contract. The client locks 1,200 ADA at the script address. The validator’s rules are simple: it releases funds only when both parties sign, or returns them to the client after a deadline passes.

The freelancer delivers the work and both sign the release. The validator checks the two signatures and the deadline, then approves a transaction that sends 1,000 ADA to the freelancer and returns 200 ADA to the client. The arithmetic is exact: 1,000 plus 200 equals the 1,200 that was locked, so nothing is created or lost.

If the work never arrives, the client waits for the deadline and then submits a refund transaction signed by the client alone. The validator checks that the deadline has passed and approves the return of the full 1,200 ADA. The escrow never needs a middleman, because the rules are enforced by the script.

What are the common mistakes?

The most common mistakes in Cardano smart contracts come from treating a validator like an account-based contract. The script cannot act, so logic that depends on the contract sending funds or calling another contract will not work as written.

  • Forgetting the off-chain half. A validator with no application to build transactions is unusable.
  • Testing only the happy path. Every rule that must reject a bad transaction needs a failing test.
  • Skipping the audit. Validators are hard to change after deployment, so review before mainnet.
  • Locking real funds on the first run. Test on the testnet with faucet funds first.
  • Ignoring execution budgets. A validator that needs more budget than allowed will always fail.

A related mistake is writing the datum and redeemer loosely. If the datum can hold any value, a spender may lock funds in a state the contract cannot release. Define the datum as a small set of states — funded, delivered, refunded — and let the validator accept only the transitions you intend.

Key takeaways

  • A Cardano smart contract is a validator script that approves or rejects spends from a script address
  • Validators read a datum, a redeemer and the transaction context, and cannot act on their own
  • Aiken is the usual starting point; Plinth suits Haskell teams and Marlowe suits financial agreements
  • Test every rule, including the cases that must fail, on the testnet before mainnet
  • Get an independent audit before the contract holds real funds

Frequently asked questions

Do I need to learn Haskell to write a Cardano smart contract?

No. Aiken is the usual choice for new projects and borrows ideas from Rust, Elm and Gleam. Plinth, formerly Plutus Tx, is the Haskell route, and OpShin lets Python developers write validators. All of them compile to the same on-chain bytecode.

How is a Cardano smart contract different from an Ethereum one?

On Cardano the contract is a validator that only approves or rejects a proposed transaction, while on Ethereum a contract can hold a balance and call other contracts. Cardano’s eUTXO model also makes a transaction’s outcome depend only on its own inputs.

What is a datum in a Cardano smart contract?

A datum is data stored with funds locked at a script address. It records the state of the agreement, such as who paid, how much, and which stage the deal is in. The validator reads the datum when it decides whether a spend is allowed.

Can a Cardano smart contract read prices or data from the internet?

No. A validator can only judge the transaction in front of it. If your contract needs outside data, an oracle must write that data into the transaction first, and the validator then checks the oracle’s signature.

How much does it cost to deploy a Cardano smart contract?

Deploying means submitting transactions, so you pay network fees for locking funds and publishing the script. Fees depend on the size of the script and the transaction, and testing on the testnet uses free faucet funds. Check the current fee schedule before you budget.

Do I need an audit before launching?

Yes, for any contract that will hold other people’s funds. A validator is hard to change after deployment, since the script address comes from the script itself. An independent audit is the standard way to catch logic errors before launch.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a smart contract on Cardano? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Smart Contract Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call