chain_getBlock - JSON-RPC Method
Description
Retrieves complete block information from the Hydration 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": [
"0x7fc8fd64a450661fd8c4a60577fe189f169d8aa97697f227a12496dba14db225"
],
"id": 1
}
Response Example
Sample response for block #9457756 captured 2025-10-01.
{
"jsonrpc": "2.0",
"result": {
"block": {
"header": {
"parentHash": "0x941ef64d8daa8fddcba9a7b698c912611e08601cf7d4be12ea3d5412a5df9a2d",
"number": "0x90505c",
"stateRoot": "0x04ddc6c3c1633a3d8a33afa961674371228050279b4507ebcd23e5b1bd5cfea1",
"extrinsicsRoot": "0xbdfd357bb38a602d496793bfd8250a9f1d866ef6143fbf4e27076a124cf4dbf0",
"digest": {
"logs": [
"0x0661757261208a2c7a1100000000",
"0x0452505352903006d1651014effe612aeb9e2bed207fca849e69a1d4594bdab580afc68677458a62ad06"
]
}
},
"extrinsics": [
"0x280403000b60e2739f9901",
"0x8e54010004670031045bd0b8b40a0a9951e16249c55b84c3011eaf9995191954..."
]
},
"justifications": null
},
"id": 1
}
Code Examples
cURL
# Get latest block
curl https://api-hydration.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-hydration.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": ["0x7fc8fd64a450661fd8c4a60577fe189f169d8aa97697f227a12496dba14db225"],
"id": 1
}'
JavaScript (fetch)
const getBlock = async (blockHash = null) => {
const params = blockHash ? [blockHash] : [];
const response = await fetch('https://api-hydration.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('0x7fc8fd64...');
console.log('Block extrinsics:', specificBlock.block.extrinsics);
Python (requests)
import requests
import json
def get_block(block_hash=None):
url = "https://api-hydration.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("0x7fc8fd64...")
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-hydration.n.dwellir.com/YOUR_API_KEY');
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