block_by_hash - Cosmos

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

Returns a block by its hash. Same response schema as block. Useful when you have a block hash from a transaction receipt or peer notification but don't know the height.

Parameters

Parameter
Type
Required
Description

hash

string

Yes

Block hash (hex-encoded, 32 bytes, with or without 0x prefix)

Request Example

# JSON-RPC over HTTP POST (canonical)
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "block_by_hash",
    "params": {
        "hash": "6E2A2A6FE7A5B4C2D4E6F8A0B2C4D6E8F0A2C4E6F8B0D2E4F6A8C0E2F4B6D8E0"
    },
    "id": "getblock.io"
}'

# URI over HTTP GET (alternate, for simple methods)
curl --location --request GET 'https://go.getblock.io/<ACCESS-TOKEN>/block_by_hash?hash="6E2A2A6FE7A5B4C2D4E6F8A0B2C4D6E8F0A2C4E6F8B0D2E4F6A8C0E2F4B6D8E0"'

Response Example

Response Parameters

Field
Type
Description

result.block_id.hash

string

Block hash (echoed)

result.block

object

Full block data (same schema as block)

Use Cases

  • Resolving a block from a known hash

  • Indexers cross-referencing block hashes with their parent chains

Error Handling

Status Code
Error Message
Cause

404

Not Found

Missing or invalid <ACCESS-TOKEN>

-32602

Invalid params

Request parameters are missing or malformed

-32603

Internal error

Server-side error while processing the request

429

Too Many Requests

Rate limit exceeded for your plan

SDK Integration

Last updated

Was this helpful?