For the complete documentation index, see llms.txt. This page is also available as Markdown.

getbestblockhash - Zcash

Example code for the getbestblockhash JSON-RPC method. Сomplete guide on how to use the getbestblockhash JSON-RPC method in GetBlock.io Web3 documentation.

This method returns the hash of the current chain tip — the most recent block accepted into the canonical chain. Lightweight alternative to getblockchaininfo when only the tip hash is needed.

Parameters

This method takes no parameters.

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getbestblockhash",
    "params": [],
    "id": "getblock.io"
}'
example.js
const axios = require('axios');

const response = await axios.post('https://go.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'getbestblockhash',
    params: [],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);
example.py
import requests

response = requests.post(
    'https://go.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'getbestblockhash',
        'params': [],
        'id': 'getblock.io'
    }
)

print(response.json())

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "00000000015aa1af4cc4e77fd576ff5b011a9ab42170bbcc008b2b9a84648165"
}

Response Parameters

Parameter
Type
Description

result

string

Hex-encoded 32-byte hash of the chain tip block

Use Cases

  • Reorg Detection: Poll the tip hash and compare to a stored previous value — a change without height advancement indicates a reorg

  • Cache Invalidation Key: Use the tip hash as a version key for cached chain-derived data

  • Lightweight Progress Signal: Cheap poll to detect chain advancement without loading full block metadata

Error Handling

Error Code
Message
Description

-32603

Internal error

Node has no blocks in state (fresh install) or failed to read the tip

Last updated

Was this helpful?