chain_subscribeNewHeads - Kusama
Example code for the chain_subscribeNewHeads WebSocket method. Complete guide on how to use chain_subscribeNewHeads WebSocket in GetBlock Web3 documentation.
Opens a subscription that streams the header of every new block as it is imported. WebSocket only. Returns a subscription id, then pushes a notification per new head.
Parameters
Subscribe
wscat -c wss://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/
# then send:
{
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "chain_subscribeNewHeads",
"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
New block number (hex)
parentHash
string
Hash of the parent block
stateRoot
string
State trie root
Use Cases
Chain Following: React to every new block in real time
Indexers: Drive ingestion from the head stream
Dashboards: Live block-height display
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?