chain_getBlock - JSON-RPC Method
Description
Retrieves complete block information from the Moonriver 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": [
"0xa39d25f8cf7ad27e6a739dc15d4d013bdc48b6e2819bb74c72822a930adb5649"
],
"id": 1
}
Response Example
{
"jsonrpc": "2.0",
"result": {
"block": {
"header": {
"parentHash": "0xa9b9ad0e896561095b8f1c177acdf7318d21469529e3352438b9edc52839eb1b",
"number": "0x1ac8b61",
"stateRoot": "0x577d42d825f054a4b33922e1a74d6593301fd3dbad05c402e151868ce664b006",
"extrinsicsRoot": "0x0f967ba2249baee6fc2a72f7479b59d5a0a4f2e179af4fd8137d039a8b2a832b",
"digest": {
"logs": [
"0x0642414245b501038501000027627b110000000094ec3341e8d27c6e199ad31f2b12ba5af2bfa586ab78e5ef874930ed4fdbcf011cb158a098ed44247b2a69960f35414cb366d57672e482668202ff1f4779300195758e67b0254ec9952eed605cfa54d8beba48889255b1f959ef5e8aab978a04",
"0x0442454546840301ee9589ed3271866acf57c01ae10d2f238f08bd1a88f96b1121a12fe5b088eb",
"0x05424142450101dae544aa5a59545f1162072633c7548ccb621a59211d2a80f5cca68e37dbf97ffaadab6343a933292307b0cbf73009836528b9579b8ebf66ebb6354ff9b57682"
]
}
},
"extrinsics": [
"0x280503000b1172ccbb9901",
"0x12c704000536005509e101464d10c6..."
]
},
"justifications": null
},
"id": 1
}
Tip: Replace the sample block reference with a recent Moonriver block hash from
chain_getFinalizedHead
.
Code Examples
- cURL
- Python
- JavaScript
- TypeScript (@polkadot/api)
# Get latest block
curl https://api-moonriver.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-moonriver.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "chain_getBlock",
"params": ["0xa39d25f8cf7ad27e6a739dc15d4d013bdc48b6e2819bb74c72822a930adb5649"],
"id": 1
}'
import requests
import json
def get_block(block_hash=None):
url = "https://api-moonriver.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("0xa39d25f8cf7ad27e6a739dc15d4d013bdc48b6e2819bb74c72822a930adb5649")
print(f"Extrinsics count: {len(specific_block['block']['extrinsics'])}")
const getBlock = async (blockHash = null) => {
const params = blockHash ? [blockHash] : [];
const response = await fetch('https://api-moonriver.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('0xa39d25f8cf7ad27e6a739dc15d4d013bdc48b6e2819bb74c72822a930adb5649');
console.log('Block extrinsics:', specificBlock.block.extrinsics);
import { ApiPromise, WsProvider } from '@polkadot/api';
async function getBlockData() {
const provider = new WsProvider('wss://api-moonriver.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