chain_subscribeAllHeads - Avail
Example code for the chain_subscribeAllHeads WebSocket method. Complete guide on how to use chain_subscribeAllHeads WebSocket in GetBlock Web3 documentation.
Streams every imported block header, including headers from non-canonical forks. WebSocket only. Broader than chain_subscribeNewHeads, which follows only the best chain.
Parameters
Subscribe
wscat -c wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/
# then send:
{
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "chain_subscribeAllHeads",
"params": []
}Subscription ID
The initial response returns the subscription id used to correlate and cancel the stream:
Notifications
While subscribed, the node pushes a notification per update:
Notification Fields
number
string
Block number (hex)
parentHash
string
Parent block hash
Use Cases
Fork Awareness: Observe competing forks as they arrive
Analytics: Measure fork/uncle rates
Indexers: Track all imported headers
Error Handling
-32603 / Internal error
Subscription error
The subscription could not be established
403 / RBAC: access denied
Access denied
The GetBlock access token is missing or incorrect
Last updated
Was this helpful?