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": [
"0x5d83e66b61701da7b6e3e8c9d8e2e57e1391e3e58e677b30e1f391d568c9ca24"
],
"id": 1
}
Response Example
{
"jsonrpc": "2.0",
"result": {
"block": {
"header": {
"parentHash": "0x4a84d1c5fc5c725b26a3c8e126d8f65e1c2d2dc5b3fcbc91e67e7637fa136789",
"number": "0x123456",
"stateRoot": "0x8f7a82e2e0f3e73f5e232e68de18144f6e7a52a6db39bb5e5e3d9ca6e1f72845",
"extrinsicsRoot": "0x2e6f9a7d2c4b3e1a8f5c6d9e4b1a7c3f8e5d2a9b6c4e1f8a5d3c2b9e7f6a4d38",
"digest": {
"logs": [
"0x0642414245b501013c0000009d2ef70f00000000",
"0x054241424501019e7b3c4e1f8a2d5c6b9e4f3a7d2c5e8b1f4a6d9c3e2b5f8a7c4d"
]
}
},
"extrinsics": [
"0x280402000b50cd548d8501",
"0x450284008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"
]
},
"justifications": null
},
"id": 1
}
Code Examples
cURL
# Get latest block
curl https://api-polkadot.n.dwellir.com \
-X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": [],
"id": 1
}'
# Get specific block
curl https://api-polkadot.n.dwellir.com \
-X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": ["0x5d83e66b61701da7b6e3e8c9d8e2e57e1391e3e58e677b30e1f391d568c9ca24"],
"id": 1
}'
JavaScript (fetch)
const getBlock = async (blockHash = null) => {
const params = blockHash ? [blockHash] : [];
const response = await fetch('https://api-polkadot.n.dwellir.com', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'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('0x5d83e66b...');
console.log('Block extrinsics:', specificBlock.block.extrinsics);
Python (requests)
import requests
import json
def get_block(block_hash=None):
url = "https://api-polkadot.n.dwellir.com"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"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("0x5d83e66b...")
print(f"Extrinsics count: {len(specific_block['block']['extrinsics'])}")
TypeScript (@polkadot/api)
import { ApiPromise, WsProvider } from '@polkadot/api';
async function getBlockData() {
const provider = new WsProvider('wss://api-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_getFinalizedHead
for finalized blocks - Block data can be large - consider using
chain_getHeader
if only header is needed