Skip to main content

chain_subscribeNewHeads

Retrieves the best header via subscription.​

For clients that require regular updates of the most important or "best" block headers as they are added to the blockchain, the chain_subscribeNewHeads RPC technique is invaluable. With no need for repetitive manual queries, this subscription-based method offers timely header dataβ€”essential for applications needing the most recent blockchain information.

Example Request and Result for chain_subscribeNewHeads method​

In this section, we provide an illustrative example of a request made to retrieve details contents using the chain_subscribeNewHeads method. Additionally, we present the resulting response containing information about getting the best header using WS subscription.

Parameters​

FieldsTypeDescription
subscriptionstringAllows the client to manage the subscription
info

The example in this section uses a non-existing project id.

Make sure you replace it with your Vara Mainnet endpoint when issuing the API calls.

Don't have a project id? Here's a straightforward guide on how to obtain one!

Retrieves the best header via subscription​

POST wss://vara-mainnet.blastapi.io/<project-id>

Request Body​

NameTypeDescription
subscriptionstring[]
{
"jsonrpc": "2.0",
"method": "chain_newHead",
"params": {
"subscription": "3pEL6Gp7F7yQluGJ",
"result": {
"parentHash": "0x45498c7ebdc8a3bc4b326c0660a4515ce795cc2a0c12fc459c6f700c40d6edd1",
"number": "0x9a2946",
"stateRoot": "0x94078bf8f35254ffba013669752428c941c24d457bd16ff97a444a8a7af61191",
"extrinsicsRoot": "0x949ca67ba029850ec54f3b768bd88f54082050381ea5b167ca14aec7749aa610",
"digest": {
"logs": [
"0x064241424534021f0000009c04f92100000000",
"0x054241424501011cdcfea6fc688511504d78f1bb32c3a2178fdaeaee7eb11234707c63d307ae7220055a65930f1aa5c26b1d9122df9720417a2c10c9fc309cb2ab8fb95836c58b"
]
}
}
}
}

Curl Request example​

wscat -c 'wss://vara-mainnet.blastapi.io/<project-id>'
# wait for connection
messasge:
{
"id": 1,
"jsonrpc": "2.0",
"method": "chain_subscribeNewHeads",
"params": []
}