chain_getBlock - JSON-RPC Method
Description#
Retrieves complete block information from the xx Network 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": [
"0x35a20ecfdb86bc6479ebe895c802ff1639ebd5821c9faa48b89fac8ddb169e87"
],
"id": 1
}
Response Example#
{
"jsonrpc": "2.0",
"result": {
"block": {
"header": {
"parentHash": "0xd0252f476d1b71dd4a724eb6d931adadb357806e80fa8dd21cb6e5ff88bf334c",
"number": "0x135d640",
"stateRoot": "0x86605e69f65e00b50f502469ddf1e0d0cf03c58718856b22899758a7211c56ab",
"extrinsicsRoot": "0xb1e40f23736f72a95e44c66df11c43f3d3d3e90e22e4f3a71dde8de0020d67c9",
"digest": {
"logs": [
"0x0642414245b501013c0000009d2ef70f00000000",
"0x054241424501019e7b3c4e1f8a2d5c6b9e4f3a7d2c5e8b1f4a6d9c3e2b5f8a7c4d"
]
}
},
"extrinsics": [
"0x280402000b50cd548d8501",
"0x450284008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"
]
},
"justifications": null
},
"id": 1
}
Tip: The example references finalized xx network block
0x135d640(decimal 20305472). Substitute a fresh hash when you need recent data.
Code Examples#
- cURL
- Python
- JavaScript
- TypeScript (@polkadot/api)
# Get latest block
curl https://api-xxnetwork.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-xxnetwork.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": ["0x35a20ecfdb86bc6479ebe895c802ff1639ebd5821c9faa48b89fac8ddb169e87"],
"id": 1
}'
import requests
import json
def get_block(block_hash=None):
url = "https://api-xxnetwork.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("0x35a20ecfdb86bc6479ebe895c802ff1639ebd5821c9faa48b89fac8ddb169e87")
print(f"Extrinsics count: {len(specific_block['block']['extrinsics'])}")
const getBlock = async (blockHash = null) => {
const params = blockHash ? [blockHash] : [];
const response = await fetch('https://api-xxnetwork.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('0x35a20ecfdb86bc6479ebe895c802ff1639ebd5821c9faa48b89fac8ddb169e87');
console.log('Block extrinsics:', specificBlock.block.extrinsics);
import { ApiPromise, WsProvider } from '@xx-network/api';
async function getBlockData() {
const provider = new WsProvider('wss://api-xxnetwork.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_getFinalizedHeadfor finalized blocks - Block data can be large - consider using
chain_getHeaderif only header is needed