Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

chain_getHeader - Avail

Example code for the chain_getHeader JSON-RPC method. Complete guide on how to use chain_getHeader JSON-RPC in GetBlock Web3 documentation.

Returns the header of a block by hash, or the latest header when the hash is omitted, including parent hash, number, state root, extrinsics root, and digest logs.

Available over both the JSON-RPC (HTTP) and WebSocket interfaces.

Parameters

Parameter
Type
Required
Description

hash

string

Optional

Block hash; omit for the latest header

Request

curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "method": "chain_getHeader",
    "params": [
    "0x8a1e6d2f0b7c4a9e3d5f1b8c2a6e4d0f9b3c7a5e1d8f2b6c4a0e9d3f7b1c5a2e6"
]
}'
example.js
const axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    id: 'getblock.io',
    method: 'chain_getHeader',
    params: [
    "0x8a1e6d2f0b7c4a9e3d5f1b8c2a6e4d0f9b3c7a5e1d8f2b6c4a0e9d3f7b1c5a2e6"
]
}, { headers: { 'Content-Type': 'application/json' } });

console.log(response.data.result);

Response

Response Fields

Field
Type
Description

number

string

Block number (hex)

parentHash

string

Hash of the parent block

stateRoot

string

State trie root

Use Cases

  • Chain Following: Read the latest header height

  • Light Reads: Fetch header without full extrinsics

  • Verification: Check parent linkage and roots

Error Handling

Error
Message
Description

-32603 / Internal error

Unknown block

No block matches the supplied hash

403 / RBAC: access denied

Access denied

The GetBlock access token is missing or incorrect

Last updated

Was this helpful?