Skip to main content
A market order executes at the current market price. Unlike a limit order, you accept any available price by setting an infinite slippage price in the datum. Market orders use a single execution fee of 0.6 ADA.
Orders are placed on-chain and require a transaction. The execution engine processes them asynchronously - execution timing depends on batcher availability and market conditions.

How market orders differ from limit orders

Base price field

Set the basePrice field in the datum to accept any price:
The numerator = 1 signals infinite slippage - the order fills regardless of the current market price.
Buying a token with ADA at any price:

Execution fee

Market orders require 1 execution step, so the total fee is:

Transaction structure

Inputs

Any user UTxOs to cover:
  • Input asset amount (what you are selling)
  • Transaction fees
  • Order collateral (minimum 2 ADA)
  • Deposit ADA for outputs

Order output

Send to the script address constructed from the script hash and optionally your stake credentials. Output value: Example - Buy 50 ADA for tokens (market):

Datum

Build the datum the same way as a limit order, with two differences:
  1. Set basePrice to [1, denominator]
  2. The beacon prefix byte is 0x01 (market)
See datum building for field reference and the full beacon algorithm.

Transaction building flow

1

Select input UTxOs

Cover all costs: input amount + 0.6 ADA fee + deposits.
2

Extract user credentials

Payment and stake key hashes from your address.
3

Calculate order index

Position of the order output in the transaction.
4

Build datum

Set basePrice: [1, tradableInput] and all other fields except beacon. See datum building.
5

Calculate beacon

Use the first input UTxO reference and order index with orderType = 'market'. Beacon prefix byte is 0x01. See beacon calculation.
6

Serialize and assemble

Serialize datum with the calculated beacon to CBOR. Calculate deposits, add collateral if needed, create the order output, and add a change output.

Important notes

The beacon calculation uses the first transaction input. Add the UTxO to transaction inputs before calculating the beacon.
  1. Order index must match the actual index of the order output in the transaction outputs array.
  2. Minimum collateral - total deposits must be at least 2 ADA.
  3. Stake credentials are optional but recommended.
  4. Asset format - ADA is ["", ""], tokens are [policyId, tokenName] in hex.
  5. Cancellation - market orders can be cancelled before execution. See order cancel.