chain_getBlock
Retrieves complete block information from Bittensor, including the block header, extrinsics, and justifications.
Why Bittensor? Build on the decentralized AI network with $3.9B+ market cap powering 80+ AI subnets with Yuma Consensus for AI model evaluation, subnet-based specialization, dual Substrate+EVM support, and incentivized AI compute marketplace.
Use Cases#
The chain_getBlock method is essential for:
- Block explorers - Display complete block information
- Chain analysis - Analyze block production patterns
- Transaction verification - Confirm extrinsic inclusion for decentralized AI inference, subnet-specific AI models, TAO staking, and cross-subnet AI collaboration
- Data indexing - Build historical blockchain databases
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
blockHash | String | No | Hex-encoded block hash. If omitted, returns latest block |
Request#
{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": ["0x2f0555cc76fc2840a25a6f3a0f0e6d0b1a6dd2e0cecc9e4c2e9e6f3a8d2e5c1b"],
"id": 1
}
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.extrinsics | Array | Array of extrinsics in the block |
justifications | Array | Block justifications (if available) |
Code Examples#
- cURL
- JavaScript
- Python
# Get latest block
curl https://api-bittensor-mainnet.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-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": ["0x2f0555cc76fc2840a25a6f3a0f0e6d0b1a6dd2e0cecc9e4c2e9e6f3a8d2e5c1b"],
"id": 1
}'
import { ApiPromise, WsProvider } from '@polkadot/api';
const provider = new WsProvider('wss://api-bittensor-mainnet.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 specific block
const blockHash = '0x2f0555cc76fc2840a25a6f3a0f0e6d0b1a6dd2e0cecc9e4c2e9e6f3a8d2e5c1b';
const block = await api.rpc.chain.getBlock(blockHash);
console.log('Block extrinsics:', block.block.extrinsics.length);
await api.disconnect();
import requests
import json
def get_block(block_hash=None):
url = 'https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY'
params = [block_hash] if block_hash else []
payload = {
'jsonrpc': '2.0',
'method': 'chain_getBlock',
'params': params,
'id': 1
}
response = requests.post(url, json=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('0x2f0555cc76fc2840a25a6f3a0f0e6d0b1a6dd2e0cecc9e4c2e9e6f3a8d2e5c1b')
print(f"Extrinsics count: {len(specific_block['block']['extrinsics'])}")
Related Methods#
chain_getBlockHash- Get block hash by numberchain_getHeader- Get block header onlychain_getFinalizedHead- Get finalized block hash