eth_getBlockTransactionCountByNumber - Ethereum
Returns the number of transactions in a block matching the given block number.

Parameters

  • QUANTITY|TAG - integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
1
params: [
2
'latest',
3
]
Copied!

Returns

  • QUANTITY - integer of the number of transactions in this block.

Example

Request
alchemyweb3.js
ethers.js
web3.py
Curl
Postman
1
// Installation instructions: https://github.com/alchemyplatform/alchemy-web3
2
3
async function main() {
4
// Import the AlchemyWeb3 library. Filepath to functions:
5
// /@alch/alchemy-web3/dist/alchemyWeb3.js
6
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
7
8
// Replace with your Alchemy API key:
9
const apiKey = "demo";
10
11
// Initialize an alchemy-web3 instance:
12
const web3 = createAlchemyWeb3(
13
`https://eth-mainnet.g.alchemy.com/v2/${apiKey}`);
14
15
// Query the blockchain (replace example parameters)
16
const count = await web3.eth.getBlockTransactionCountByNumber({
17
tag: 'latest',
18
});
19
20
// Print the output to console
21
console.log(count);
22
}
23
24
main();
Copied!
1
// Installation instructions: https://docs.ethers.io/v5/getting-started/#installing
2
3
async function main() {
4
const { ethers } = require("ethers");
5
6
// Replace with your Alchemy API key:
7
const apiKey = "demo";
8
9
// Initialize an ethers instance
10
const provider = new ethers.providers.AlchemyProvider("homestead", apiKey);
11
12
// Query the blockchain (replace example parameters)
13
const count = await provider.getBlockTransactionCountByNumber({
14
tag: 'latest',
15
});
16
17
// Print the output to console
18
console.log(count);
19
}
20
21
main()
Copied!
1
# Installation Instructions: https://web3py.readthedocs.io/en/latest/quickstart.html#installation
2
3
from web3 import Web3, HTTPProvider
4
5
#Replace with your Alchemy API key:
6
apiKey = "demo"
7
8
# Initialize a Web3.py instance
9
web3 = Web3(Web3.HTTPProvider('https://eth-mainnet.alchemyapi.io/v2/'+apiKey))
10
11
# Query the blockchain (replace example parameters)
12
count = web3.eth.get_block_transaction_count({
13
hash: "0xc0f490",
14
})
15
16
# Print the output to console
17
print(count)
Copied!
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByNumber","params":["latest"],"id":0}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_getBlockTransactionCountByNumber",
7
"params":["latest"],
8
"id":0
9
}
Copied!
Result
1
{
2
"jsonrpc": "2.0",
3
"id": 0,
4
"result": "0xee"
5
}
Copied!
Ethereum API
Alchemy Documentation
Copy link