getbestblockheightandhash - Zcash

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

bashcurl --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"
}'

example.js

javascriptconst 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);

example.py

pythonimport 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())

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "getbestblockheightandhash",
            "params": [],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;
    
    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "result": {
        "height": 3487829,
        "hash": [
            225,
            140
        ]
    },
    "id": "getblock.io"
}

Response Parameters

ParameterTypeDescription
heightintegerHeight of the chain tip
hashstringHex-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

Error CodeMessageDescription
-32601Method not foundEndpoint runs a client that doesn't expose this Zebra-specific extension
-32603Internal errorNode has no blocks in state