⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

eth_getTransactionCount

Returns the number of transactions sent from an address (nonce).

When to Use This Method

Use eth_getTransactionCount to:

  • Get Current Nonce - Required for signing transactions
  • Prevent Nonce Errors - Ensure correct transaction ordering
  • Track Account Activity - Count transactions sent
  • Manage Batch Transactions - Sequential nonce management
  • Recover Stuck Transactions - Replace transactions with same nonce

Parameters

  1. Address - DATA, 20 Bytes

    • Address to get transaction count for
  2. Block Parameter - QUANTITY|TAG

    • latest - Latest block
    • earliest - Genesis block
    • pending - Pending state
    • Block number
{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8",
"latest"
],
"id": 1
}

Returns

QUANTITY - Number of transactions sent from this address.

Implementation Examples

import { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY');

// Get nonce for address
const address = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8';
const nonce = await provider.getTransactionCount(address);
console.log('Current nonce:', nonce);

// Get pending nonce (includes pending transactions)
const pendingNonce = await provider.getTransactionCount(address, 'pending');
console.log('Pending nonce:', pendingNonce);