githubEdit

getblockhash - Bitcoin

Example code for the getblockhash JSON-RPC method. Complete guide on how to use getblockhash JSON-RPC in GetBlock Web3 documentation.

This method returns the hash of the block at the specified height in the best-block-chain.

Parameters

Parameter
Type
Required
Description

height

number

Yes

The block height (index).

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getblockhash",
    "params": [820000],
    "id": "getblock.io"
}'

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "000000000000000000046b9302e08c16ea186950f42a5498320ddd1bd7ab3428"
}

Response Parameters

Field
Type
Description

result

string

The block hash as a hex string.

Use Case

The getblockhash method is essential for:

  • Looking up blocks by height

  • Building block explorer navigation

  • Iterating through the blockchain

  • Fetching specific historical blocks

  • Implementing chain traversal algorithms

  • Building height-based block references

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN.

-8

Block height out of range

The specified height doesn't exist.

Integration Notes

The getblockhash method helps developers:

  • Navigate blockchain by height

  • Build block explorers

  • Implement chain scanning

  • Create historical analysis tools

  • Support height-based lookups

Last updated

Was this helpful?