eth_getBlockTransactionCountByNumber - Base

Example code for the eth_getBlockTransactionCountByNumber JSON-RPC method. Complete guide on how to use eth_getBlockTransactionCountByNumber JSON-RPC in GetBlock Web3 documentation.

The eth_getBlockTransactionCountByNumber method returns the number of transactions in a block matching the given block number. This provides a quick way to assess block activity without fetching full block data.

Parameters

Parameter
Type
Required
Description

blockParameter

string

Yes

Block number in hex, or "latest", "earliest", "pending"

Request

cURL
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_getBlockTransactionCountByNumber",
    "params": ["latest"],
    "id": "getblock.io"
}'

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0xc"
}

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

string

Number of transactions in the block (hex)

Use Cases

  • Block Monitoring: Track transaction counts in recent blocks

  • Network Activity: Measure current network throughput

  • Historical Analysis: Analyze transaction patterns over time

  • Resource Planning: Estimate processing requirements

  • Dashboard Metrics: Display real-time block statistics

Error Handling

Error Code
Message
Description

-32602

Invalid params

Invalid block number format

-32603

Internal error

Block not found

Web3 Integration

Last updated

Was this helpful?