Ethereum

Ethereum

eth_getBlockTransactionCountByHash

eth_getBlockTransactionCountByHash returns just one number: how many transactions are packed into the block with a given 32-byte hash on Ethereum mainnet. It's the lightweight cousin of eth_getBlockByHash — when all you need is the count, you skip transferring the entire block body. Because you address by hash, the answer is tied to one specific block regardless of any reorg around that height. The result is a hex integer, with 0x0 meaning an empty block (which still happens on Ethereum even though one is proposed every 12-second slot). Call it at https://ethereum.therpc.io/YOUR_API_KEY (chain ID 1, native coin ETH).

Use cases

  • Cheap fullness check. See how busy a block was without paying to download its transaction list — handy when scanning many blocks.
  • Indexer reconciliation. After ingesting a block, compare the count you stored against this method's answer to confirm you didn't drop a transaction.
  • Throughput sampling. Run it across a set of known block hashes to chart transactions-per-block and, given the 12-second slot cadence, infer rough TPS over a stretch of the chain.

Parameters

#NameTypeRequiredDescription
1blockHashstring (hex)YesThe hash of the block to count transactions in.

Response

TypeDescription
string (hex)Hex-encoded transaction count. "0x0" means the block is empty.

Example request

curl https://ethereum.therpc.io/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": ["0x0000000000000000000000000000000000000000000000000000000000000000"],
"id": 1
}'

Try it live in the Ethereum playground.

Errors & troubleshooting

CodeMessageCause
-32602Invalid paramsBlock hash is malformed or not 32 bytes.

Common pitfalls

  • An unknown hash yields null, not 0x0. Null-check before you parseInt — feeding null to a hex parser is a quiet source of NaN counts.
  • If you already hold a height and don't need a hash to pin a specific block across reorgs, eth_getBlockTransactionCountByNumber does the same job and lets you pass tags like latest or finalized directly.

Supported networks

  • Mainnet — Chain ID: 1
  • Sepolia — Chain ID: 11155111

See also

Parameters

0x-prefixed 32-byte block hash

curl https://ethereum.therpc.io/YOUR_API_KEY \
-X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_getBlockTransactionCountByHash","params":[""]}'

Ready to call this in production?

Free tier covers personal projects. Pay-as-you-go scales without a card.