chain_subscribeNewHead

Retrieves the best header via subscription

The chain_subscribeNewHead method is meant to give clients access to the most recent block headers in real time. For applications that need to know instantly when new blocks are added to the blockchain, this subscription-based strategy is essential since it guarantees timely data delivery without requiring repetitive queries.

Example Request and Result for chain_subscribeNewHead method

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

Parameters

FieldsTypeDescription

subscription

string

Allows the client to manage the subscription

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

subscription

string

[]

{
  "jsonrpc": "2.0",
  "method": "chain_newHead",
  "params": {
    "subscription": "zrBfK4zVLZwi7W27",
    "result": {
      "parentHash": "0x584661f8cff31a1e1fbf19da104b028dee180d87e04f28aaa3631a0b2d3c4f2b",
      "number": "0x9a2823",
      "stateRoot": "0xeb7105f6b33409d7d45bf0d5907d10923ca3d70298454d04e782893c7bef6439",
      "extrinsicsRoot": "0x53d4b4ed6b5ba0cb54cce6b639f98593184ef6ac0b887f01e187fc29afc0758a",
      "digest": {
        "logs": [
          "0x06424142453402210000007903f92100000000",
          "0x05424142450101fa3b1d23a94155410ef59845b34e2563b9ecae0a307dcef1e1e2975c41dc5c116e519312ec9cad20c044f13da734ea2ade101e4fa55fcf020751e2365a99d484"
        ]
      }
    }
  }
}

Curl Request example

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

Last updated