POST
/
8763cb5a211e1d4345acd51bde484c00
/
ext
/
bc
/
C
/
rpc
curl --request POST \
  --url https://nd-418-459-126.p2pify.com/8763cb5a211e1d4345acd51bde484c00/ext/bc/C/rpc \
  --header 'Content-Type: application/json' \
  --data '{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_getBlockTransactionCountByHash",
  "params": [
    "0x3e76cf8acbbc6d07a2ae51a7af0457589264e67aaf0e94e2d2e0c09e5b6c04db"
  ]
}'
{
  "jsonrpc": "<string>",
  "id": 123,
  "result": "<string>"
}

Avalanche API method that returns the number of transactions in a block specified by block hash. This information can be useful for analytics purposes.

Get you own node endpoint today

Start for free and get your app to production levels immediately. No credit card required.

You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

  • hash — the block hash of the requested block.

Response

  • quantity — an integer value representing how many transactions are included in the block.

eth_getBlockTransactionCountByHash code examples

const Web3 = require("web3");

const NODE_URL = "CHAINSTACK_NODE_URL";

const web3 = new Web3(NODE_URL);



async function getTransactionsCount(blockHash) {

  const count = await web3.eth.getBlockTransactionCount(blockHash)

  console.log(count);

}



getTransactionsCount('0x49b96784d08c346d56ace5b1ebfee608479ec3bd51e7d11b3d955578efde648c')

Use case

eth_getBlockTransactionCountByHash is a useful tool for analyzing transaction volume on the Avalanche blockchain. On average, a new block is generated on the Avalanche mainnet every 2 seconds, resulting in approximately 1,700 blocks per hour. Using the web3.js library, one can inspect the past 1,700 blocks starting from the latest block, retrieve the hash of each block, and use eth_getBlockTransactionCountByHash to find the number of transactions in each block.

index.js
const Web3 = require("web3");

const NODE_URL = "CHAINSTACK_NODE_URL";

const web3 = new Web3(NODE_URL);



async function retrieveTransactionsCount() {

  // Get the current block number

  const currentBlockNumber = await web3.eth.getBlockNumber();



  // Calculate the block number from one hour ago

  const oneHourAgoBlockNumber = currentBlockNumber - 1700; // 1700 blocks/hr on average on the Avalanche mainnet

  

  // Initialize a variable to store the total number of transactions

  let totalTransactionCount = 0;



  // Loop through all blocks from the current block number to the block number from one hour ago

  for (let block = currentBlockNumber; block > oneHourAgoBlockNumber; block--) {



    // Get the hash of each block

    const getBlockHash = await web3.eth.getBlock(block, false);

    const blockHash = getBlockHash.hash



    // Get the number of transactions in this block using each hash

    const transactionCount = await web3.eth.getBlockTransactionCount(blockHash);



    // Add the number of transactions in this block to the total

    totalTransactionCount += transactionCount;



    console.log(`Block #${block} has ${transactionCount} transactions.`);

  }



  console.log(`The total number of transactions in the previous hour is: ${totalTransactionCount}`);

}





retrieveTransactionsCount();

This example connects to an Avalanche node using the web3.js library. The retrieveTransactionsCount function gets the current block number, calculates the block number from one hour ago, and uses a for loop to iterate through all blocks in that range.

The function then retrieves the hash of each block and the number of transactions in each block and adds it to a total transaction count. The final result, the total number of transactions in the previous hour, is logged to the console.

This is a good example of how you can combine different methods.

Body

application/json

Response

200 - application/json
The block information

The response is of type object.