chain_getBlockHash
Description
Returns the block hash for a given block number. Needed when pinning queries to historical state or verifying inclusion proofs.
Parameters
Position | Type | Description |
---|---|---|
0 (optional) | string or number | Block number (hex or decimal). Omit to get the latest block hash. |
Request Example
{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": ["0x9fbc37"],
"id": 1
}
Response Example
{
"jsonrpc": "2.0",
"id": 1,
"result": "0xae7ff263b3ca7ce2fa9c1729a4a0fd20b62d6b3befe7d9bd584afc30afc61c06"
}
Code Examples
JavaScript (polkadot.js)
const hash = await api.rpc.chain.getBlockHash(10_468_407);
console.log(hash.toHex());
Python (requests)
payload = {"jsonrpc": "2.0", "method": "chain_getBlockHash", "params": [10468407], "id": 1}
resp = requests.post(
"https://api-astar.n.dwellir.com/YOUR_API_KEY",
headers={"Content-Type": "application/json"},
data=json.dumps(payload)
)
print(resp.json()["result"])