For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_getTransactionCount - Optimism

Example code for the eth_getTransactionCount json-rpc method. Сomplete guide on how to use eth_getTransactionCount json-rpc in GetBlock.io Web3 documentation.

This method returns the number of transactions sent from a specific address, which is also known as the nonce. The nonce is critical for transaction ordering and preventing replay attacks. When sending transactions, you need to use the correct nonce value. Using 'pending' as the block parameter returns the nonce including pending transactions, which is essential for sending multiple transactions in sequence.

Parameters

Parameter
Type
Description
Required

address

DATA, 20 Bytes

The address to get the transaction count for.

Yes

block

QUANTITY|TAG

Block number in hex, or 'latest', 'earliest', 'pending'.

Yes

Request Sample

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

Response

A successful response returns the following:

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

Response Parameters

Field
Type
Description

result

string (hex)

Number of transactions sent from this address. Equivalent to the account nonce.

Use Case

The eth_getTransactionCount method is commonly used for:

  • Transaction nonce management

  • Account activity analysis

  • Transaction sequencing

  • Wallet implementation

Error handling

Status Code
Error Message
Cause

404

Not Found

Missing or invalid ACCESS_TOKEN.

-32602

Invalid argument

  • Invalid address

  • Block parameter not recognized

Integration with Web3

The eth_getTransactionCount method helps developers to:

  • Manage nonces automatically when sending transactions

  • Prevent duplicate transactions by checking the latest nonce

  • Build reliable wallet transaction pipelines

  • Track account activity in explorers and dashboards

  • Detect pending transactions by comparing pending vs latest values

  • Support batch transaction systems that depend on precise nonce control

Last updated

Was this helpful?