Skip to main content
Every on-chain order carries a datum that encodes the order parameters. This page covers how to build each field.

Datum structure

Field reference

Price calculation

Price is the output / input ratio, stored as [numerator, denominator].
Buying token with ADA:
  • Input: ADA
  • Output: Token
  • Price: tokenAmount / adaAmount = [tokenAmount, adaAmount]
Example: Buy 100 tokens for 50 ADA -> [100, 50] = 2 tokens per ADA

Input amount

  • Buy order: tradableInput = ADA amount the user is willing to spend
  • Sell order: tradableInput = token amount the user is selling

Beacon calculation

The order beacon is a 20-byte unique identifier that prevents beacon collisions. Its primary purpose is to prevent beacon collisions - ensuring that every order placed on-chain has a globally unique identifier. Structure:
  • Byte 0: order type (0 = limit, 1 = market)
  • Bytes 1-19: first 19 bytes of a blake2b-224 hash
All numeric indices must be encoded as big-endian uint64 (8 bytes).

Algorithm

1

Create empty beacon

28 bytes of zeros: 0000...0000
2

Serialize datum with empty beacon

Convert the datum (with empty beacon) to CBOR format.
3

Hash the datum

Apply blake2b-224 to the serialized datum CBOR bytes.
4

Build beacon preimage

Concatenate in order:
  • Transaction hash (32 bytes) of one of the transaction inputs
  • Output index (8 bytes, big-endian uint64)
  • Order index (8 bytes, big-endian uint64)
  • Datum hash (28 bytes) from step 3
5

Calculate final beacon

Apply blake2b-224 to the preimage, take the first 19 bytes, and prefix with the order type byte (0 or 1). Result: 20 bytes.

Implementation

Where:
  • outputReference - one of the transaction inputs (UTxO reference)
  • orderIndex - index of the order output in the transaction (BigInt)
  • orderType - 'limit' or 'market'

Real example

Buy order: 50 ADA for NIGHT token at ~4.2 tokens per ADA. View transaction on CardanoScan