eth_getBlockTransactionCountByHash - Base

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

The eth_getBlockTransactionCountByHash method returns the number of transactions in a block matching the given block hash. This is useful for quickly determining block activity without fetching full block data.

Parameters

Parameter
Type
Required
Description

blockHash

string

Yes

32-byte hash of the block

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": ["0x849a3ac8f0d81df1a645701cdb9f90e58500d2eabb80ff3b7f4e8c13f025eff2"],
    "id": "getblock.io"
}'

The JSON-RPC response returns the transaction count as a hex string (for example, "0x8"). Convert it to a decimal integer in your client (examples above use parseInt(..., 16) or int(..., 16)).

Response

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

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

string

Number of transactions in the block (hex)

Use Cases

  • Block Analysis: Quickly assess block activity levels

  • Network Monitoring: Track transaction throughput

  • Data Validation: Verify block data integrity

  • Indexing Optimization: Plan batch processing based on tx count

  • Statistics Collection: Gather block-level metrics

Error Handling

Error Code
Message
Description

-32602

Invalid params

Invalid block hash format

-32603

Internal error

Block not found

Web3 Integration

Last updated

Was this helpful?