Book a free call

How to Create a DEX on Cardano, Step by Step

A DEX on Cardano is a set of validators, an off-chain app and a liquidity pool built on the eUTXO model. Here is the model choice, the toolchain and the build steps.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Create a DEX on Cardano, Step by Step
On this page

Short answer

A decentralised exchange (DEX) on Cardano is an application that lets users swap native tokens without a central operator, using smart contracts called validators that run on Cardano's extended UTXO (eUTXO) model. Trades are settled by transactions that the validators approve, and liquidity comes from pools funded by users.

What is a DEX on Cardano?

A decentralised exchange (DEX) on Cardano is an application that lets users swap native tokens without a central operator, using smart contracts called validators that run on Cardano's extended UTXO (eUTXO) model. Trades are settled by transactions that the validators approve, and liquidity comes from pools funded by users.

Cardano's model shapes how a DEX works. Unlike account-based chains, where a contract holds a shared balance, Cardano tracks value as unspent transaction outputs (UTXOs). Each output carries a value, a spending condition and a piece of data called a datum. A DEX keeps its pool state in UTXOs, and a swap consumes the pool UTXO and creates a new one with the updated balances.

That design has a direct consequence: a single pool UTXO can only be spent by one transaction at a time. A DEX that puts all liquidity in one UTXO will queue trades one by one, so builders split pools across many UTXOs or use an off-chain batcher to combine requests. For the general idea of a DEX, see what a DEX is.

Order book or AMM: which model fits Cardano?

A DEX on Cardano is usually an automated market maker (AMM), not an order book. An AMM prices trades from a formula applied to a pool, so it needs no matching engine and no list of open orders. An order book matches buy and sell orders at set prices, which is closer to a centralised exchange but harder to run on Cardano's model.

The reason is concurrency. An order book needs shared, constantly changing state, which the eUTXO model handles poorly, because each state change is a separate UTXO spend. An AMM pool can be split into many UTXOs, each holding part of the liquidity, so many trades can run in parallel. Most Cardano DEXs therefore use the AMM model, sometimes with a batcher that groups requests into one transaction.

Model How price is set Fit for Cardano Main trade-off
AMM, constant product Pool ratio formula Good, pools split across UTXOs Slippage on large trades
AMM with batcher Pool ratio, batched orders Good, high throughput Batcher is a trusted step
Order book Matching buy and sell orders Hard, shared state Complex, slow settlement
Hybrid AMM plus limit orders Possible, more work Two systems to maintain

Start with a constant-product AMM. It is the simplest model to build, test and audit, and it matches how most existing Cardano DEXs work. Add order-book features only after the AMM is live and audited.

What do you need to build it?

Building a DEX on Cardano needs three layers: on-chain validators, off-chain code that builds transactions, and a front end. The validators are written in a language that compiles to UPLC, the bytecode every Cardano node runs. The off-chain code runs in the user's wallet and in your own services, and it builds the transactions the validators check.

Aiken is the usual choice for new projects. It is purpose-built for Cardano validators, with syntax borrowed from Rust, and it ships a compiler, a test runner and a tool that emits a CIP-57 Plutus blueprint on every build. Plutus, written in Haskell, is the original language and suits teams that already know Haskell. Plutarch suits performance-critical validators, and OpShin suits Python teams.

Tool What it does Best for
Aiken Validator language, compiles to UPLC Most new DEX projects
Plutus (Plinth) Haskell validators, on and off chain Haskell teams
Cardano CLI Build and submit transactions Testing and deployment
Lucid or Mesh SDK Off-chain transaction building Front end and wallet flows
Cardano node Syncs the chain, submits transactions Every deployment
Blockfrost or Koios Chain data through an API Indexing pools and prices

You also need a testnet wallet with test ADA, a way to index pool state so the front end can show prices, and a plan for fees. Every transaction pays a fee, and the DEX usually takes a small fee on each swap, which goes to liquidity providers. A general guide to building a DEX is at how to build a DEX.

How to build it in seven steps

A Cardano DEX is built in stages, with the validator first and the front end last. Each stage can be tested on its own before the next one starts.

  1. Pick the model and the tokens. Choose constant-product AMM, decide which token pairs to launch with, and set the swap fee.
  2. Design the pool UTXOs. Decide how the pool is split across UTXOs, what datum each one carries, and how the batcher groups requests.
  3. Write the validators in Aiken. Write the swap, deposit and withdrawal validators, with checks on the pool ratio, the fee and the datum.
  4. Test the validators locally. Run Aiken's test runner to check each validator, including the failure cases where a transaction should be rejected.
  5. Build the off-chain code. Write the transaction building with Lucid or Mesh, the wallet connection, and the code that reads pool state for prices.
  6. Deploy to testnet and run swaps. Deploy the validators on Cardano testnet, seed a pool with test tokens, and run swaps, deposits and withdrawals end to end.
  7. Audit, then deploy to mainnet. Get an independent audit of the validators, fix what it finds, deploy to mainnet, and seed the first pool with real liquidity.

The audit is not optional. A DEX holds other people's tokens, and a bug in a validator can drain a pool. Budget for the audit before you start, and do not launch mainnet liquidity until it is done. For teams that want help, DEX development companies for startups lists firms that build exchanges.

How does a swap actually work?

A swap on a Cardano DEX moves tokens through the pool in one transaction. The user submits a transaction that spends the pool UTXO and the user's own UTXO, and the validator checks that the pool's new balances match the pricing formula and that the fee was paid. If the checks pass, the transaction creates a new pool UTXO with the updated balances and an output that pays the user.

The pricing formula for a constant-product pool is simple: the product of the two token balances stays the same before and after the trade, apart from the fee. A large trade moves the price more than a small one, which is why large swaps suffer slippage.

The batcher pattern helps here: it collects several swap requests and settles them in one transaction, so each user pays one shared fee instead of a full transaction fee each.

Example (hypothetical): a pool holds 200,000 ADA and 100,000 USDC. The product is 200,000 x 100,000 = 20,000,000,000. A user swaps 10,000 ADA into the pool, so the ADA balance becomes 210,000 and the USDC balance must become 20,000,000,000 / 210,000 = 95,238.10.

The user receives 100,000 - 95,238.10 = 4,761.90 USDC. The price the user got is worse than the pool's starting price of 2 ADA per USDC, because the trade itself moved the ratio.

What to test before mainnet

Testing a Cardano DEX means testing the validators, the transaction building and the front end as a system. Unit tests catch logic errors in the validators, but the failures that drain pools usually come from the interaction between the on-chain checks and the off-chain code that builds transactions.

  • Validator failure cases. Test every transaction the validator should reject: wrong amounts, wrong datum, missing fee, expired order.
  • Slippage and rounding. Test small and large trades, and check that rounding never pays out more than the pool holds.
  • Concurrent swaps. Test two swaps against the same pool UTXO at once, and confirm one fails cleanly instead of corrupting state.
  • Batcher behaviour. Test what happens when the batcher is slow, offline or receives a bad request.
  • Wallet and front-end flows. Test with the wallets your users actually use, on testnet, before mainnet.
  • Fee and minimums. Confirm the fee math on every path, including deposits, withdrawals and failed swaps.

Run the full test suite on testnet with real users if you can. A small group of testers will find front-end and wallet problems that unit tests never touch.

What are the common mistakes?

The most common mistakes when building a DEX on Cardano are putting all liquidity in one UTXO, skipping the audit, and treating the batcher as free.

  • One UTXO for the whole pool. A single pool UTXO can only be spent once per block, so trades queue up. Split the pool or use a batcher.
  • Skipping the audit. Validators hold user funds. An unaudited DEX is a risk no liquidity provider should accept.
  • Trusting the batcher blindly. A batcher that groups requests is a point of failure. Plan for it being offline or slow.
  • Wrong fee math. Rounding errors in fees can pay out more than the pool holds, or take more than users agreed to.
  • No slippage protection. Users need a minimum-received amount, or a large trade can settle at a bad price.
  • Launching with no liquidity. A DEX with an empty pool has no trades. Seed the first pools before announcing the launch.

Key takeaways

  • A Cardano DEX swaps native tokens using eUTXO validators
  • Most Cardano DEXs use the AMM model, not an order book
  • Aiken is the usual validator language for new projects
  • Split pools across UTXOs or use a batcher to handle concurrency
  • Audit the validators before seeding mainnet liquidity

Frequently asked questions

What is a DEX on Cardano?

A DEX on Cardano is an application that lets users swap native tokens without a central operator. Smart contracts called validators, running on Cardano's extended UTXO model, check each trade, and liquidity comes from pools funded by users. Trades settle as transactions that the validators approve.

Is it better to build an AMM or an order book on Cardano?

An AMM is usually better. It prices trades from a pool formula, needs no matching engine, and its pool can be split across many UTXOs so trades run in parallel. An order book needs shared, constantly changing state, which the eUTXO model handles poorly.

Which language should I use for a Cardano DEX?

Aiken is the usual choice for new projects: it is purpose-built for Cardano validators and compiles to UPLC, the bytecode nodes run. Plutus suits Haskell teams, Plutarch suits performance-critical validators, and OpShin suits Python teams. All of them compile to the same on-chain target.

How much does it cost to build a DEX on Cardano?

The cost depends on the model, the audit and the team. The build itself is a few months of work for a small team, and an independent audit of the validators is a separate cost that should be budgeted from the start. Transaction fees on testnet are free test ADA, but mainnet fees are real.

What is a batcher in a Cardano DEX?

A batcher is an off-chain service that collects swap requests and settles them together in one transaction. It solves the concurrency problem of the eUTXO model, where one pool UTXO can only be spent once per block. The trade-off is that the batcher becomes a point of failure to plan around.

Do I need an audit before launching a Cardano DEX?

Yes. A DEX holds other people's tokens, and a bug in a validator can drain a pool in a single transaction. Get an independent audit of the validators, fix what it finds, and only then deploy to mainnet and seed liquidity.

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 DEX on Cardano and need a team that knows eUTXO? Talk to Hertiv.

A senior engineer replies within one business day. Or see our DEX 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