DocumentationAPI Reference~1300 words
Source: docs/api/WEBSOCKET.en.md

#Indexer WebSocket Feed

This page specifies the indexer WebSocket feed at /ws for developers building live client views. It covers the chain tip, new pearls, trades, second candles, and address activity. Load the initial data through the Indexer HTTP API.

Each text frame is one JSON object. The running indexer validates client frames with its inbound schema and stamps every event with a monotonic seq. The same trade is sent again, with the same txid, when it moves through queued, mempool, confirmed, or dropped. Upsert by txid.

The shared package schema (WsServerMsg) does not include seq. Clients talking to the indexer still read seq. That field is the resume cursor.

#Connect

Open ws://127.0.0.1:3001/ws on a local indexer. A gateway may expose the same path on another host.

RuleValue
Path/ws
FrameText JSON. Binary frames get { "op": "error", "message": "binary frames are not supported" }
Channels in one subAt most 50
Channels on one connectionAt most 100
unsub channels in one messageAt most 200
Client payloadDefault max 16 KiB
Server protocol pingEvery 30,000 ms. Reply to the WebSocket ping. A client that stays silent through a ping interval is treated as timed out
Replay bufferThe latest 2,048 events
Coalesce window100 ms. Snapshot updates collapse to the latest one, trades to the latest status per txid, and candles to the latest event per pearl, interval, and bucket start

The handshake URL also accepts sinceSeq or lastSeq (/ws?sinceSeq=120). A non-integer value fails the upgrade with HTTP 400.

Channel names match ^(tip|tokens:new|token:[0-9a-f]{64}:\d+|address:[a-z0-9]+)$.

ChannelPayload
tipChainTip
tokens:newToken
token:<tokenId>{ type: "token", token }, { type: "trade", trade }, or { type: "candle", interval, t, candle }
address:<addr>{ type: "trade", trade } or { type: "refresh" }

<tokenId> is the pearl outpoint, including the colon. <addr> is the Taproot address in lowercase. Do not URL-encode the channel name.

#Client messages

opFieldsEffect
subch (1 to 50 names). Optional sinceSeq or lastSeqSubscribe. If a sequence is set, the server replays buffered events on those channels with seq greater than that value
unsubch (up to 200 names)Drop those subscriptions
pingnoneServer answers { "op": "pong" }
resumesinceSeq. Optional chReplay. If ch is set, subscribe to those channels and replay them. If ch is omitted, replay the channels already held on the connection
json
{
  "op": "sub",
  "ch": [
    "tip",
    "tokens:new",
    "token:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1"
  ],
  "sinceSeq": 120
}
json
{ "op": "unsub", "ch": ["tokens:new"] }
json
{ "op": "ping" }
json
{ "op": "resume", "sinceSeq": 120 }

An empty ch on sub does nothing. Crossing 100 subscriptions on the connection returns an error and does not add the new names. The error message is subscription limit exceeded (max 100).

#Server messages

Every live event looks like this. seq starts at 1 and increases by 1 for each event the process accepts, across all channels.

json
{ "op": "event", "seq": 121, "ch": "tip", "data": {} }

#Chain tip

tip is pushed when a new block arrives or the mempool fee suggestion changes. Inside a 100 ms window, only the latest tip is sent.

json
{
  "op": "event",
  "seq": 121,
  "ch": "tip",
  "data": {
    "network": "testnet",
    "height": 10243,
    "hash": "00000000000000000000000000000000000000000000000000000000000000ab",
    "time": 1763741094000,
    "mempoolTxs": 4,
    "feeRate": 2
  }
}

feeRate is a suggestion in grains per virtual byte. hash is 64 lowercase hex characters. time is Unix milliseconds.

#New pearls

tokens:new carries a full pearl when a launch is seen. The object below is a shape example for a pearl still on the curve. Prices in it are placeholders for the types. They are not a quote.

status is "curve" or "amm". "amm" means the pearl is harvested and trading in its on-chain pool. step is how many of the 800 curve layers have been sold, including unconfirmed trades. confirmedStep is the confirmed count. progressBps is floor(step * 10,000 / 800), from 0 to 10,000. nextPrice is grains per layer (1,000,000 tokens), without the trade fee. On an amm pearl it is the latest trade price in the same units. marketCap is nextPrice times totalLots. poolValue is the pool's PRL in grains. graduatedAt is the harvest time, or null while status is "curve".

json
{
  "op": "event",
  "seq": 122,
  "ch": "tokens:new",
  "data": {
    "id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
    "genesisOutpoint": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb:0",
    "name": "Pearl Cat",
    "symbol": "PCAT",
    "image": "/api/v1/tokens/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%3A1/image",
    "creator": "tprl1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
    "status": "curve",
    "ammState": null,
    "ammReserveTokens": null,
    "step": 0,
    "confirmedStep": 0,
    "totalLots": 1000,
    "poolAddress": null,
    "poolOutpoint": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
    "poolValue": "10000",
    "nextPrice": "100000000",
    "marketCap": "100000000000",
    "holders": 1,
    "volume24h": "0",
    "progressBps": 0,
    "createdHeight": null,
    "createdAt": 1763740000000,
    "graduatedAt": null
  }
}

Optional metadata, when present, is description (max 280), website, twitter, and telegram (each max 200). symbol matches ^[A-Z0-9]{2,10}$. name is 1 to 32 characters.

On a harvested pearl, status is "amm", step stays 800, graduatedAt is a timestamp, and both ammState and ammReserveTokens are integers. ammState is in -1,610 through 4,607. ammReserveTokens counts whole tokens in the pool. A curve pearl must send both AMM fields as null.

#One pearl

token:<id> uses data.type.

A state push (type "token") replaces the client's copy of that pearl. Several updates inside the coalesce window become one push, placed after trades in that batch.

json
{
  "op": "event",
  "seq": 130,
  "ch": "token:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
  "data": {
    "type": "token",
    "token": {
      "id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
      "genesisOutpoint": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb:0",
      "name": "Pearl Cat",
      "symbol": "PCAT",
      "image": "/api/v1/tokens/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa%3A1/image",
      "creator": "tprl1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
      "status": "curve",
      "ammState": null,
      "ammReserveTokens": null,
      "step": 5,
      "confirmedStep": 0,
      "totalLots": 1000,
      "poolAddress": null,
      "poolOutpoint": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc:0",
      "poolValue": "10000",
      "nextPrice": "100000000",
      "marketCap": "100000000000",
      "holders": 2,
      "volume24h": "0",
      "progressBps": 62,
      "createdHeight": 10240,
      "createdAt": 1763740000000,
      "graduatedAt": null
    }
  }
}

progressBps of 62 is floor(5 * 10,000 / 800). A displayed percent is not recomputed from a guessed price.

A trade push (type "trade") is a new trade or a status change. kind is launch, buy, sell, transfer, or graduate. buy and sell include phase (curve or amm). AMM buys and sells leave stepFrom and stepTo as null. tokens is the whole-token size. grains is the principal in grains: what a buyer adds to the pool, or what a seller takes out. Other kinds use "0". feeGrains is the trade fee, not the miner fee. seq on the trade is the queue's per-pearl number, or null when the trade did not go through the queue. That number is not the WebSocket seq on the envelope.

json
{
  "op": "event",
  "seq": 131,
  "ch": "token:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
  "data": {
    "type": "trade",
    "trade": {
      "txid": "1111111111111111111111111111111111111111111111111111111111111111",
      "tokenId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
      "kind": "buy",
      "phase": "curve",
      "address": "tprl1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
      "counterparty": null,
      "tokens": 5000000,
      "grains": "100000000",
      "feeGrains": "1000000",
      "stepFrom": 0,
      "stepTo": 5,
      "status": "mempool",
      "seq": 1,
      "height": null,
      "time": 1763741094000
    }
  }
}

5,000,000 tokens is five layers. The grain amounts show the field types. They are not a curve quote. When this buy confirms, the same txid arrives again with status "confirmed" and a height.

#Second candles

Subscribe to token:<id> for updates to second candles when a buy or sell arrives, confirms, or is dropped. Use the Indexer HTTP API for the recent candle series, including empty buckets that carry forward the previous close, and for intervals of 1m and longer.

Field in dataTypeMeaning
typestringAlways "candle"
intervalstring1s, 5s, 15s, or 30s
tintegerBucket start in Unix milliseconds
candleobject or nullReplacement candle for this interval and bucket start. Delete the bucket if the server sends null

The candle uses the HTTP response fields. Its pending field is true while any trade in the bucket is unconfirmed. Once all trades in the bucket confirm, it becomes false. A dropped trade can produce a replacement candle, including a carry-forward candle with n: 0, or a deletion if the bucket no longer has a candle.

json
{
  "op": "sub",
  "ch": ["token:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1"]
}

An event for a one-second bucket containing an unconfirmed trade:

json
{
  "op": "event",
  "seq": 132,
  "ch": "token:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
  "data": {
    "type": "candle",
    "interval": "1s",
    "t": 1763741094000,
    "candle": {
      "t": 1763741094000,
      "o": "10000",
      "h": "12000",
      "l": "10000",
      "c": "12000",
      "v": "50000",
      "tokens": 1000000,
      "n": 1,
      "pending": true
    }
  }
}

An event that deletes that bucket:

json
{
  "op": "event",
  "seq": 133,
  "ch": "token:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:1",
  "data": {
    "type": "candle",
    "interval": "1s",
    "t": 1763741094000,
    "candle": null
  }
}

#One address

address:<addr> sends trades that involve that address, in the same trade shape, or a refresh:

json
{
  "op": "event",
  "seq": 140,
  "ch": "address:tprl1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",
  "data": { "type": "refresh" }
}

refresh means outputs or the PRL balance changed. Load GET /api/v1/address/:a/utxos and GET /api/v1/address/:a/portfolio again. Repeated refreshes inside the coalesce window become one message.

#Heartbeat and errors

A client ping returns:

json
{ "op": "pong" }

Bad JSON, an unknown op, a bad channel, or too many channels returns:

json
{ "op": "error", "message": "invalid JSON message" }

The message text is the first schema issue, or a short fixed string such as invalid JSON message. The socket stays open after an error frame. Fix the next message. A slow client is dropped when its buffered outbound bytes pass 512 KiB. Above 64 KiB the server may skip a snapshot (tip, pearl state, or refresh) and keep trade frames.

#Replay

Replay returns buffered events whose seq is greater than sinceSeq, in order, for the named channels. The default cap is the buffer size (2,048). If the cursor is older than the buffer, the oldest events still stored are sent, and the gap is not announced. After every reconnect, the client subscribes again and refreshes the HTTP trade list and the pearl. The client keeps the highest seq it has applied.

Snapshot frames can also be dropped for a slow socket. Trades and tokens:new are not dropped for that reason.

#Next

To place a buy, sell, harvest, or swap, use the queue service. To load the snapshot this socket updates, use the Indexer HTTP API.

NACRE · The first keyless launchpad on Pearl