chain_getBlock - JSON-RPC Method
Description
Returns the full block for a given block hash.
Typical Flow
- Fetch latest finalized head with chain_getFinalizedHead
- Use that hash as the parameter to
chain_getBlock
Code Examples
- cURL
- JavaScript
# 1) Get finalized head
HEAD=$(curl -s https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"chain_getFinalizedHead","params":[],"id":1}' | jq -r '.result')
# 2) Get the 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":["'"$HEAD"'"],"id":2}'
async function rpc(method, params = []) {
const res = await fetch('https://api-bittensor-mainnet.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', method, params, id: 1 })
});
return (await res.json()).result;
}
const head = await rpc('chain_getFinalizedHead');
const block = await rpc('chain_getBlock', [head]);
console.log(block.block.header.number);