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

eth_getBlockTransactionCountByHash - Ethereum

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

This method returns the number of transactions in a block, identified by block hash, hex-encoded. A lightweight alternative to fetching the full block when only the transaction count is needed — for example, to compute activity metrics without materializing the transaction list.

Parameters

Parameter
Type
Required
Description

blockHash

string

Yes

32-byte block hash

Request

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

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

console.log(response.data.result);

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0xde"
}

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

string

Hex-encoded transaction count in the block

Use Cases

  • Block Activity Metrics: Cheap poll of per-block transaction count for dashboards

  • Iteration Bounds: Determine the loop bound for iterating transactions by (blockHash, index)

  • Reorg-Safe Activity Snapshots: Get per-block counts referenced by hash rather than number

Error Handling

Error Code
Message
Description

-32602

Invalid params

Block hash is malformed

-32603

Internal error

Node failed to look up the block

Web3 Integration

Was this helpful?