Skip to main content
The onChainOrder contract handles placing limit and market orders on-chain. Orders are submitted to the contract and executed by the protocol’s execution engine when price conditions are met.
Orders are placed on-chain and require a transaction. The execution engine processes them asynchronously — execution timing depends on batcher availability and market conditions.

Contract information

9e130eb0323f31df50bfbb731f35f5a795a630ef727b4ba272460b55

Transaction structure

Inputs

Any user UTxOs to cover:
  • Input asset amount (what the user is 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 the user’s stake credentials. Address construction:
import { credentialsToBech32Address } from '@splashprotocol/sdk';

const SCRIPT_HASH = '9e130eb0323f31df50bfbb731f35f5a795a630ef727b4ba272460b55';

const orderAddress = await credentialsToBech32Address(
  network,
  {
    hash: SCRIPT_HASH,
    type: 'script',
  },
  userStakeCredentials
    ? {
        hash: userStakeCredentials,
        type: 'pubKey',
      }
    : undefined
);
Output value:
AssetAmount
Input assetinputAmount
ADA (execution fee)feePerExStep * (orderType === 'limit' ? 3 : 1)
ADA (deposit)depositAdaForOrder + depositAdaForReceive
ADA (collateral)Additional if total < 2 ADA
Where:
  • feePerExStep = 600_000 lovelace (0.6 ADA per execution step)
  • Limit orders require 3x fee (1.8 ADA), market orders 1x fee (0.6 ADA)
  • depositAdaForOrder = minimum ADA to store the order UTxO
  • depositAdaForReceive = minimum ADA for the user’s output after execution
  • Additional collateral added if total < 2 ADA minimum

Order types

Limit order

  • Execution fee: 1.8 ADA (3 x 0.6 ADA)
  • Beacon prefix: 0x00
  • Executes only when market price reaches the specified price
  • Can be cancelled by the user

Market order

  • Execution fee: 0.6 ADA (1 x 0.6 ADA)
  • Beacon prefix: 0x01
  • Executes at current market price
  • Can be cancelled by the user

Deposit ADA calculation

Order output must contain enough ADA to cover:
1

Execution fee

Limit order: 1.8 ADA (3 x 0.6 ADA). Market order: 0.6 ADA (1 x 0.6 ADA).
2

Minimum UTxO deposit

Calculated based on output value size (input asset + ADA) and datum size (~200–300 bytes). Use Cardano’s minUTxOValue formula or protocol parameters.
3

Collateral

Minimum total 2 ADA. If execution fee + UTxO deposit is less than 2 ADA, add the difference.
4

Receiving deposit

ADA needed for the user’s output after execution. Depends on expected output asset and address.
Formula:
Order Output = Input Asset
             + Execution Fee (0.6 or 1.8 ADA)
             + UTxO Deposit (calculated)
             + Additional Collateral (if needed to reach 2 ADA minimum)
             + Receiving Deposit (for user's output)
Example — Buy order, 50 ADA for tokens (market):
ComponentAmount
Input asset50 ADA
Execution fee0.6 ADA
UTxO deposit~1.5 ADA
Receiving deposit~1.5 ADA
Additional collateral0 ADA (total already > 2)
Total~53.6 ADA

Transaction building flow

1

Select input UTxOs

Cover all costs: input amount + fees + deposits.
2

Extract user credentials

Payment and stake key hashes from the user’s address.
3

Calculate order index

Position of the order output in the transaction.
4

Build datum

Construct all fields except beacon. See datum building.
5

Calculate beacon

Use the first input UTxO reference and order index. 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 with script hash, stake credentials, value, and datum. Add a change output for the user.
See a real transaction example on CardanoScan.

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. Additional collateral is added automatically if needed.
  3. Stake credentials are optional but recommended for proper fund ownership and staking rewards.
  4. Price inversion — buy orders require inverted price ratios (denom/num instead of num/denom).
  5. Asset format — ADA is ["", ""], tokens are [policyId, tokenName] in hex.
  6. Execution — orders are executed by protocol batchers when conditions are met.