chain_getBlockHash
Returns the block hash for a given block number on Asset Hub.
Use Cases#
- Historical queries - Convert block numbers to hashes
- Block navigation - Navigate blockchain history for native stablecoin transfers (USDC, USDT), DOT staking and governance, and cross-chain asset management via XCM
- Data indexing - Build block number to hash mappings
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
blockNumber | Number | No | Block number. If omitted, returns latest block hash |
Request#
{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [1000000],
"id": 1
}
Code Examples#
- cURL
- JavaScript
- Python
curl https://api-asset-hub-polkadot.n.dwellir.com/<YOUR_API_KEY>/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlockHash",
"params": [1000000],
"id": 1
}'
import { ApiPromise, WsProvider } from '@polkadot/api';
const provider = new WsProvider('wss://api-asset-hub-polkadot.n.dwellir.com/YOUR_API_KEY');
const api = await ApiPromise.create({ provider });
// Get hash for specific block number
const blockNumber = 1000000;
const blockHash = await api.rpc.chain.getBlockHash(blockNumber);
console.log(`Block ${blockNumber} hash:`, blockHash.toHex());
await api.disconnect();
import requests
def get_block_hash(block_number=None):
url = 'https://api-asset-hub-polkadot.n.dwellir.com/<YOUR_API_KEY>/YOUR_API_KEY'
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, json=payload)
return response.json()['result']
block_hash = get_block_hash(1000000)
print(f'Block hash: {block_hash}')
Related Methods#
chain_getBlock- Get block by hashchain_getHeader- Get block header