eth_getblocktransactioncountbyhash

Optimism RPC

How to use it

// yarn add @tatumio/tatum

import { TatumSDK, Optimism, Network } from '@tatumio/tatum'
  
const tatum = await TatumSDK.init<Optimism>({network: Network.OPTIMISM})

const response = await tatum.rpc.getBlockTransactionCountByHash('0x00ccb8a97e104e09ebec66f9c58aca7d42df4fbb7cfcf1a9ff4cb7fc08814cd6')

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs

Overview

eth_getBlockTransactionCountByHash is a method used to fetch the number of transactions in a block by the block's hash. It is useful when you want to know the total number of transactions included in a specific block and don't want to retrieve the entire block data. This method can be used in various scenarios, such as monitoring the network activity or estimating transaction confirmation times.

Parameters

This method requires a single parameter:

  • blockHash: The hash of the target block for which the transaction count will be retrieved. It should be a valid 32-byte hex string.

Example of the parameter:

  • blockHash: "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"

Return

The method returns a single value:

  • transactionCount: The total number of transactions included in the specified block. It is returned as a hexadecimal value.

Examples

JSON-RPC request

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getBlockTransactionCountByHash",
  "params": [
    "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"
  ]
}

JSON-RPC response

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0xa"
}

In this example, the block with the hash "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238" has a total of 10 transactions (indicated by the hexadecimal value "0xa").