WebSocket API
The public API is a JSON-over-WebSocket protocol exposed on ws://localhost:8172
by default.
There are two message classes:
- request/response messages, which always carry an
id - notifications, which never carry an
id
Requests
Every request includes:
id: client-selected unsigned integertype: request discriminator
Example:
{"id":1,"type":"Status"}
Responses
Every successful or failed request receives a response with the same id.
Example:
{
"id": 1,
"type": "status",
"data": []
}
Main Request Types
Status: returns indexed block spansVariants: returns pallet and event variant metadataGetEvents: queries indexed events for a key, optionally paginated withbeforeand optionally enriched with finalized proofs viaincludeProofsSubscribeStatus: subscribes to status changesSubscribeEvents: subscribes to updates for one keyUnsubscribeStatus: removes a status subscriptionUnsubscribeEvents: removes an event subscriptionSizeOnDisk: returns current database size
Status
Request:
{"id":1,"type":"Status"}
Response type: status
Response payload:
- array of indexed block spans
- each span has
startandend
Example:
{
"id": 1,
"type": "status",
"data": [
{"start": 1, "end": 1000}
]
}
Variants
Request:
{"id":2,"type":"Variants"}
Response type: variants
Response payload:
- array of pallets
- each pallet has
index,name, andevents - each event variant has
indexandname
Example:
{
"id": 2,
"type": "variants",
"data": [
{
"index": 42,
"name": "Referenda",
"events": [
{"index": 0, "name": "Submitted"}
]
}
]
}
Example GetEvents
{
"id": 3,
"type": "GetEvents",
"key": {
"type": "Custom",
"value": {"name": "ref_index", "kind": "u32", "value": 42}
},
"limit": 100,
"before": null,
"includeProofs": false
}
Request fields:
key: query keylimit: optionalu16, default100before: optional event cursorincludeProofs: optional boolean, defaultfalse
Response type: events
Response payload:
key: the queried keyevents: matching event refs, newest firstdecodedEvents: decoded payloads when event storage is enabledproofsByBlock: omitted unless proofs were requested;nullif requested but unavailableproofsStatus: omitted unless proofs were requested
Proofs are only returned while the indexer is running in finalized mode. When
available, the response includes one proof object per returned block containing
the finalized block hash, header, System.Events storage key/value pair, and the
storage proof for that value.
Each EventRef contains:
blockNumbereventIndex
Each decoded event object contains:
specVersionpalletNameeventNamepalletIndexvariantIndexeventIndexfields
Each proof object contains:
blockNumberblockHashheaderstorageKeystorageValuestorageProof
proofsStatus contains:
availablereasonmessage
Example response:
{
"id": 3,
"type": "events",
"data": {
"key": {"type": "Custom", "value": {"name": "ref_index", "kind": "u32", "value": 42}},
"events": [
{"blockNumber": 50, "eventIndex": 3}
],
"decodedEvents": [
{
"blockNumber": 50,
"eventIndex": 3,
"event": {
"specVersion": 1234,
"palletName": "Referenda",
"eventName": "Submitted",
"palletIndex": 42,
"variantIndex": 0,
"eventIndex": 3,
"fields": {
"index": 42
}
}
}
],
"proofsByBlock": [
{
"blockNumber": 50,
"blockHash": "0xabc123...",
"header": {
"parent_hash": "0x...",
"number": 50,
"state_root": "0x...",
"extrinsics_root": "0x...",
"digest": {"logs": []}
},
"storageKey": "0x26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7",
"storageValue": "0x...",
"storageProof": ["0x..."]
}
],
"proofsStatus": {
"available": true,
"reason": "included",
"message": "Finalized event proofs included."
}
}
}
If proofs were requested while the indexer is not running in finalized mode,
proofsByBlock is returned as null and proofsStatus.reason is
finalized_proofs_unavailable.
Composite Custom Keys
Composite keys use an ordered array of typed values:
{
"id": 3,
"type": "GetEvents",
"key": {
"type": "Custom",
"value": {
"name": "item_revision",
"kind": "composite",
"value": [
{"kind": "bytes32", "value": "0xabc123..."},
{"kind": "u32", "value": 7}
]
}
}
}