How market orders differ from limit orders
Base price field
Set thebasePrice field in the datum to accept any price:
numerator = 1 signals infinite slippage - the order fills regardless of the current market price.
- Buy (ADA -> token)
- Sell (token -> ADA)
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:- Set
basePriceto[1, denominator] - The beacon prefix byte is
0x01(market)
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.
- Order index must match the actual index of the order output in the transaction outputs array.
- Minimum collateral - total deposits must be at least 2 ADA.
- Stake credentials are optional but recommended.
- Asset format - ADA is
["", ""], tokens are[policyId, tokenName]in hex. - Cancellation - market orders can be cancelled before execution. See order cancel.