rest/blockhashbyheight - Bitcoin
Example code for the rest/blockhashbyheight REST endpoint. Complete guide on how to use the rest/blockhashbyheight REST endpoint in the GetBlock Web3 documentation.
This endpoint returns the hash of the block at a given height on the main chain.
Parameters
height
integer
path
Yes
Block height on the main chain
format
string
path
Yes
Response format appended to the height: json, hex, or bin
Request
curl --location --request GET 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/rest/blockhashbyheight/967816.json'const response = await fetch(
'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/rest/blockhashbyheight/967816.json'
);
console.log(await response.json());import requests
response = requests.get('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/rest/blockhashbyheight/967816.json')
print(response.json())Response
{
"blockhash": "000000000000000000019c481c042c0625abe1dc04fe26795e2e24b152791e5f"
}Response Parameters
blockhash
string
Hash of the block at the requested height
Use Cases
Height to Hash: Resolve a height before calling an endpoint that takes a hash
Chain Checks: Confirm which block occupies a height after a reorganization
Indexing: Walk heights sequentially while building a local index
Error Handling
400
Bad request
The path is malformed, or a hash or height is invalid
403
Forbidden
Missing or invalid ACCESS-TOKEN
404
Not found
No object matches the requested hash, height, or outpoint
500
Internal error
The node failed to process the request
Last updated
Was this helpful?