⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

chain_getBlockHash

Description#

Retrieves the block hash for a specific block number. When called without parameters, returns the hash of the latest block. This method is commonly used to get block identifiers for historical queries.

Parameters#

ParameterTypeRequiredDescription
blockNumbernumberNoBlock number to get hash for. If omitted, returns latest block hash

Returns#

FieldTypeDescription
resultstringHex-encoded block hash

Request Example#

{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [1000000],
"id": 1
}

Response Example#

{
"jsonrpc": "2.0",
"result": "0xe56606c30688c0f08d2eca5eb28e02e9878ce9c28998ecc7541c68277e2bc94b",
"id": 1
}

Code Examples#

import requests
import json

def get_block_hash(block_number=None):
url = "https://api-asset-hub-polkadot.n.dwellir.com"
headers = {
"Content-Type": "application/json"
}

params = [block_number] if block_number is not None else []

payload = {
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": params,
"id": 1
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
return response.json()["result"]

# Get genesis block hash
genesis_hash = get_block_hash(0)
print(f"Genesis block: {genesis_hash}")