curl --request POST \
--url https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": [
"0x53e84f299e6893680383c6a53329574122a7292e5bb9397bb6a0b51b4db5957a"
],
"id": 1
}'
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x5"
}
Returns the number of transactions in a block by its hash.
curl --request POST \
--url https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": [
"0x53e84f299e6893680383c6a53329574122a7292e5bb9397bb6a0b51b4db5957a"
],
"id": 1
}'
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x5"
}
eth_getBlockTransactionCountByHash
JSON-RPC method returns the number of transactions in a block by its hash. This method provides a lightweight way to get transaction count information without retrieving the full block data, making it efficient for block analysis and statistics.
blockHash
(string, required) — The 32-byte hash of the blocknull
if the block is not found.
result
— The number of transactions in the block as a hexadecimal string0x
prefix0x0
indicates an empty block (no transactions)null
indicates the block hash doesn’t exist// Convert hex count to decimal
const txCount = parseInt("0x5", 16); // 5 transactions
// Get transaction count for a block by hash on Hyperliquid
const getBlockTransactionCountByHash = async (blockHash) => {
const response = await fetch('https://hyperliquid-mainnet.core.chainstack.com/YOUR_ENDPOINT/evm', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getBlockTransactionCountByHash',
params: [blockHash],
id: 1
})
});
const data = await response.json();
if (data.result === null) {
throw new Error('Block not found');
}
return {
hex: data.result,
decimal: parseInt(data.result, 16)
};
};
// Analyze multiple blocks for activity patterns
const analyzeBlockActivity = async (blockHashes) => {
const results = [];
for (const hash of blockHashes) {
try {
const count = await getBlockTransactionCountByHash(hash);
results.push({
blockHash: hash,
transactionCount: count.decimal
});
} catch (error) {
console.error(`Error processing block ${hash}:`, error);
results.push({
blockHash: hash,
transactionCount: null,
error: error.message
});
}
}
// Calculate statistics
const validCounts = results
.filter(r => r.transactionCount !== null)
.map(r => r.transactionCount);
if (validCounts.length === 0) {
return { results, statistics: null };
}
const statistics = {
totalBlocks: validCounts.length,
totalTransactions: validCounts.reduce((sum, count) => sum + count, 0),
averageTransactions: validCounts.reduce((sum, count) => sum + count, 0) / validCounts.length,
maxTransactions: Math.max(...validCounts),
minTransactions: Math.min(...validCounts),
emptyBlocks: validCounts.filter(count => count === 0).length
};
return { results, statistics };
};
// Usage examples
const blockHash = "0x53e84f299e6893680383c6a53329574122a7292e5bb9397bb6a0b51b4db5957a";
getBlockTransactionCountByHash(blockHash)
.then(count => console.log(`Block has ${count.decimal} transactions`))
.catch(error => console.error('Error:', error));
// Analyze multiple blocks
const blockHashes = [
"0x53e84f299e6893680383c6a53329574122a7292e5bb9397bb6a0b51b4db5957a",
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
];
analyzeBlockActivity(blockHashes)
.then(analysis => console.log('Block Activity Analysis:', analysis))
.catch(error => console.error('Error:', error));
eth_getBlockByHash
curl -X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByHash","params":["0x53e84f299e6893680383c6a53329574122a7292e5bb9397bb6a0b51b4db5957a"],"id":1}' \
https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm
eth_getBlockTransactionCountByHash
method is essential for applications that need to:
eth_getBlockByHash
if you need the full block data including transaction details.Successful response with the transaction count
The response is of type object
.