getbestblockheightandhash - Zcash
Example code for the getbestblockheightandhash JSON-RPC method. Complete guide on how to use the getbestblockheightandhash JSON-RPC method in GetBlock.io Web3 documentation.
This method returns the height and hash of the current chain tip together in a single call. A Zebra-specific extension that avoids the round-trip of calling getblockcount and getbestblockhash separately — useful for consistent tip snapshots in indexing pipelines.
Parameters
This method takes no parameters.
Request
curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "getbestblockheightandhash",
"params": [],
"id": "getblock.io"
}'const axios = require('axios');
const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
jsonrpc: '2.0',
method: 'getbestblockheightandhash',
params: [],
id: 'getblock.io'
}, {
headers: { 'Content-Type': 'application/json' }
});
console.log(response.data.result);import requests
response = requests.post(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
headers={'Content-Type': 'application/json'},
json={
'jsonrpc': '2.0',
'method': 'getbestblockheightandhash',
'params': [],
'id': 'getblock.io'
}
)
print(response.json())Response
{
"jsonrpc": "2.0",
"result": {
"height": 3487829,
"hash": [
225,
140
]
},
"id": "getblock.io"
}Response Parameters
height
integer
Height of the chain tip
hash
string
Hex-encoded 32-byte hash of the chain tip block
Use Cases
Consistent Tip Snapshots: Retrieve height and hash atomically — critical when the chain may advance between calls
Indexer Anchor Points: Anchor an indexing run to a specific tip position for later resumption
Reorg-Safe Progress Tracking: Track chain progress with the height+hash pair to detect both advancement and reorgs
Error Handling
-32601
Method not found
Endpoint runs a client that doesn't expose this Zebra-specific extension
-32603
Internal error
Node has no blocks in state
Last updated
Was this helpful?