eth_getBlockTransactionCountByHash
curl --request POST \
--url https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7 \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": [
"0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8"
]
}
'import requests
url = "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": ["0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'eth_getBlockTransactionCountByHash',
params: ['0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8']
})
};
fetch('https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_getBlockTransactionCountByHash',
'params' => [
'0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getBlockTransactionCountByHash\",\n \"params\": [\n \"0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getBlockTransactionCountByHash\",\n \"params\": [\n \"0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getBlockTransactionCountByHash\",\n \"params\": [\n \"0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}Ethereum node API
eth_getBlockTransactionCountByHash | Ethereum
Ethereum API method that returns the number of transactions in a block specified by block hash. This information can be useful for analytics purposes.
POST
/
0a9d79d93fb2f4a4b1e04695da2b77a7
eth_getBlockTransactionCountByHash
curl --request POST \
--url https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7 \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": [
"0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8"
]
}
'import requests
url = "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": ["0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'eth_getBlockTransactionCountByHash',
params: ['0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8']
})
};
fetch('https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_getBlockTransactionCountByHash',
'params' => [
'0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7"
payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getBlockTransactionCountByHash\",\n \"params\": [\n \"0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getBlockTransactionCountByHash\",\n \"params\": [\n \"0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://nd-422-757-666.p2pify.com/0a9d79d93fb2f4a4b1e04695da2b77a7")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getBlockTransactionCountByHash\",\n \"params\": [\n \"0x633a90413361fe1889d1e5ab4cb222608d224c458b30289b8390496a3fab29d8\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}Ethereum API method that returns the number of transactions in a block specified by block hash. This information can be useful for analytics purposes.
This example connects to an Ethereum node using the ethers.js library. The
Get your own node endpoint todayStart 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
Learn more about the
ChainstackProvider in ethers.js: ethers ChainstackProvider Documentation.const ethers = require("ethers");
// Create a ChainstackProvider instance for Ethereum mainnet
const chainstack = new ethers.ChainstackProvider("mainnet");
const getTransactionsCount = async (blockHash) => {
const count = await chainstack.send("eth_getBlockTransactionCountByHash", [
blockHash,
]);
console.log(count);
};
getTransactionsCount(
"0xbff1ae920dd96597dd486d68b2b7c045c3bdc6d6c64dfeb9759499c9e8ca6737"
);
from web3 import Web3
node_url = "CHAINSTACK_NODE_URL"
web3 = Web3(Web3.HTTPProvider(node_url))
print(web3.eth.get_block_transaction_count("0xbff1ae920dd96597dd486d68b2b7c045c3bdc6d6c64dfeb9759499c9e8ca6737"))
Use case
eth_getBlockTransactionCountByHash is a useful tool for analyzing transaction volume on the Ethereum blockchain. For instance, a new block is generated on the Ethereum blockchain every 12 seconds, resulting in approximately 300 blocks per hour. Using the ethers.js library, one can inspect the past 300 blocks starting from the latest block and use eth_getBlockTransactionCountByHash to find the number of transactions in each block.
index.js
const ethers = require("ethers");
// Create a ChainstackProvider instance for Ethereum mainnet
const provider = new ethers.ChainstackProvider("mainnet");
async function retrieveTransactionsCount() {
// Get the current block number
const currentBlockNumber = await provider.getBlockNumber();
// Calculate the block number from one hour ago
const oneHourAgoBlockNumber = currentBlockNumber - 300; // 300 blocks/hr on average on the Ethereum 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 provider.getBlock(block);
const blockHash = getBlockHash.hash
// Get the number of transactions in this block using each hash
const transactionCount = await provider.send("eth_getBlockTransactionCountByHash", [blockHash]);
// Add the number of transactions in this block to the total
totalTransactionCount += Number(transactionCount);
console.log(`Block #${block} has ${Number(transactionCount)} transactions.`);
}
console.log(`The total number of transactions in the previous hour is: ${totalTransactionCount}`);
}
retrieveTransactionsCount();
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.Last modified on June 25, 2026
Was this page helpful?