chain_getBlock - JSON-RPC Method
Description#
Retrieves complete block information from the Polkadot blockchain, including the block header, extrinsics, and justifications. When called without parameters, returns the latest block.
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
blockHash | string | No | Hex-encoded block hash. If omitted, returns the latest block |
Returns#
| Field | Type | Description |
|---|---|---|
block | object | Complete block data |
block.header | object | Block header information |
block.header.parentHash | string | Hash of the parent block |
block.header.number | string | Block number (hex-encoded) |
block.header.stateRoot | string | Root of the state trie |
block.header.extrinsicsRoot | string | Root of the extrinsics trie |
block.header.digest | object | Block digest items |
block.extrinsics | array | Array of extrinsics in the block |
justifications | array | Block justifications (if available) |
Request Example#
{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": [
"0xe56606c30688c0f08d2eca5eb28e02e9878ce9c28998ecc7541c68277e2bc94b"
],
"id": 1
}
Response Example#
{
"jsonrpc": "2.0",
"result": {
"block": {
"header": {
"parentHash": "0xcc0a7a965f9b98d3c5eb46b99c1fad579b17c5e94b1254ab53dbf395ad193821",
"number": "0x968a6e",
"stateRoot": "0xa0c05728445046b290704283e4fc80ff8a14719e6619dbec3e80adb6cef5ea4a",
"extrinsicsRoot": "0xf6950859a3e2700f3c476af69d99bfe5a785cf88dcb654935cffc40ad4edd916",
"digest": {
"logs": [
"0x066175726120aaafbd0800000000",
"0x0452505352905c983a7a7e537ca58173cb3ff825519600bd99ef93cf49a62db9e68a62767aa44a22b206"
]
}
},
"extrinsics": [
"0x1296010005010091037f8ce5060944c1a94713758c661330f1d2a34f33019a23fb6032f57b66ec93beb6295a02298329d63687e1d2ab801fd67a19189d1b795629a55c23a46d4817b6e2f3c37a48d2f22ee1770bc599c9276d8a945cf9f4ebe38fca8090e8b80e80c2bd383d960c066175726120aaafbd0800000000",
"..."
]
},
"justifications": null
},
"id": 1
}
Tip: The example above references finalized block
0x968a6e(decimal 9,865,838). Update the hash if you need metadata from a more recent block.
Code Examples#
- cURL
- Python
- JavaScript
- TypeScript (@polkadot/api)
# Get latest block
curl https://api-asset-hub-polkadot.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": [],
"id": 1
}'
# Get specific block
curl https://api-asset-hub-polkadot.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": ["0xe56606c30688c0f08d2eca5eb28e02e9878ce9c28998ecc7541c68277e2bc94b"],
"id": 1
}'
import requests
import json
def get_block(block_hash=None):
url = "https://api-asset-hub-polkadot.n.dwellir.com/YOUR_API_KEY"
headers = {
"Content-Type": "application/json"
}
params = [block_hash] if block_hash else []
payload = {
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": params,
"id": 1
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
data = response.json()
if "error" in data:
raise Exception(f"RPC Error: {data['error']}")
return data["result"]
# Get latest block
latest_block = get_block()
block_number = int(latest_block["block"]["header"]["number"], 16)
print(f"Latest block number: {block_number}")
# Get specific block
specific_block = get_block("0xe56606c30688c0f08d2eca5eb28e02e9878ce9c28998ecc7541c68277e2bc94b")
print(f"Extrinsics count: {len(specific_block['block']['extrinsics'])}")
const getBlock = async (blockHash = null) => {
const params = blockHash ? [blockHash] : [];
const response = await fetch('https://api-asset-hub-polkadot.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'chain_getBlock',
params: params,
id: 1
})
});
const data = await response.json();
return data.result;
};
// Get latest block
const latestBlock = await getBlock();
console.log('Latest block number:', parseInt(latestBlock.block.header.number, 16));
// Get specific block
const specificBlock = await getBlock('0xe56606c30688c0f08d2eca5eb28e02e9878ce9c28998ecc7541c68277e2bc94b');
console.log('Block extrinsics:', specificBlock.block.extrinsics);
import { ApiPromise, WsProvider } from '@polkadot/api';
async function getBlockData() {
const provider = new WsProvider('wss://api-asset-hub-polkadot.n.dwellir.com');
const api = await ApiPromise.create({ provider });
// Get latest block
const latestHash = await api.rpc.chain.getBlockHash();
const latestBlock = await api.rpc.chain.getBlock(latestHash);
console.log('Latest block:', {
number: latestBlock.block.header.number.toNumber(),
hash: latestHash.toHex(),
extrinsicsCount: latestBlock.block.extrinsics.length
});
// Get block at specific height
const blockHash = await api.rpc.chain.getBlockHash(1000000);
const block = await api.rpc.chain.getBlock(blockHash);
// Parse extrinsics
block.block.extrinsics.forEach((ex, index) => {
console.log(`Extrinsic ${index}:`, ex.toHuman());
});
await api.disconnect();
}
Use Cases#
- Block Explorers: Display block details and transaction history
- Chain Analysis: Analyze block production patterns and extrinsic distribution
- Transaction Verification: Confirm transaction inclusion in specific blocks
- Network Monitoring: Track block production and finalization
- Data Indexing: Build databases of historical blockchain data
Block Structure Details#
Header Fields#
- parentHash: Links blocks in the chain
- number: Sequential block identifier
- stateRoot: Merkle root of all account states
- extrinsicsRoot: Merkle root of all extrinsics
- digest: Contains consensus-related data (BABE, GRANDPA)
Extrinsics#
Each extrinsic in the array is hex-encoded and contains:
- Signature (for signed extrinsics)
- Method call data
- Additional parameters (nonce, tip, mortality)
Related Methods#
chain_getBlockHash- Get block hash by numberstate_getStorage- Query state at specific blockstate_getMetadata- Get runtime metadatasystem_health- Check node sync status
Notes#
- Block numbers are hex-encoded in responses
- Extrinsics are returned as hex-encoded SCALE data
- Justifications are only present for finalized blocks with GRANDPA proofs
- Latest block may not be finalized - use
chain_getFinalizedHeadfor finalized blocks - Block data can be large - consider using
chain_getHeaderif only header is needed