Docs
Docs
Home
Getting Started
Agent Tooling
CLI
Supported Chains
Acala
Aptos
Arbitrum
Arc
Asset Hub
Astar
Avalanche
Base
Berachain
Bifrost
Binance Smart Chain
Bittensor
Blast
Boba Network
Bridge Hub
Celo
Centrifuge
Chiliz
Cronos
Enjin
Ethereum
Etherlink
Flow EVM Gateway
Gnosis
Hydration
Hyperliquid
Immutable
Ink
IoTeX
Kusama
Linea
LISK
Manta Atlantic
Manta Pacific
Mantle
MegaETH
Monad
Movement
Neuroweb
opBNB
Optimism
Plasma
Polkadot
Polygon
Pulsechain
Robinhood
Ronin
Scroll
Sonic
Starknet
Taiko
Tempo
Sui
TRON
Unichain
Viction
World Chain
XDC Network
XX Network
Zetachain
zkSync Era
Zora
Supported ChainsZetachainJSON-RPC APIAccount Methods

eth_getTransactionCount - Zetachain RPC Method

Get the number of transactions sent from an address (nonce) on Zetachain. Essential for nonce management, transaction signing, and detecting stuck transactions.

Zetachain RPC endpoint: endpoint URLs, plans and pricing.

Returns the number of transactions sent from an address on Zetachain, commonly known as the nonce. The nonce is required for every outbound transaction to ensure correct ordering and prevent replay attacks.

Why Zetachain? Build on the universal omnichain blockchain enabling cross-chain smart contracts across 50+ chains including Bitcoin with native Bitcoin support, 50+ chain interoperability via UNISON, no bridging required, and partnerships with Curve and SushiSwap.

When to Use This Method

eth_getTransactionCount is essential for cross-chain dApp developers, Bitcoin DeFi builders, and teams requiring native multi-chain interoperability:

  • Transaction Signing - Get the correct nonce before building and signing a new transaction on Zetachain
  • Nonce Gap Detection - Compare latest and pending nonces to identify stuck or dropped transactions in the mempool
  • Account Activity Analysis - Track the total number of outgoing transactions from any address on omnichain DeFi, native Bitcoin smart contracts, cross-chain asset management, and unified liquidity aggregation
  • Batch Transaction Sequencing - Assign sequential nonces when submitting multiple transactions from the same address
JSON-RPC request
{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionCount",
  "params": [
    "0x5F0b1a82749cb4E2278EC87F8BF6B618dC71a8bf",
    "latest"
  ],
  "id": 1
}

Code Examples

Bash
curl -X POST https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_getTransactionCount",
    "params": [
      "0x5F0b1a82749cb4E2278EC87F8BF6B618dC71a8bf",
      "latest"
    ],
    "id": 1
  }'

Common Use Cases

1. Safe Transaction Sender with Nonce Management

Build a transaction sender that handles nonces correctly on Zetachain:

JavaScript
import { JsonRpcProvider, Wallet, parseEther } from 'ethers';

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

class TransactionSender {
  constructor(privateKey) {
    this.wallet = new Wallet(privateKey, provider);
    this.localNonce = null;
  }

  async getNextNonce() {
    // Get the pending nonce from the network
    const pendingNonce = await provider.getTransactionCount(
      this.wallet.address, 'pending'
    );

    // Use whichever is higher: local tracker or network pending
    if (this.localNonce === null || pendingNonce > this.localNonce) {
      this.localNonce = pendingNonce;
    }

    const nonce = this.localNonce;
    this.localNonce++;
    return nonce;
  }

  async sendTransaction(to, valueEth) {
    const nonce = await this.getNextNonce();

    const tx = await this.wallet.sendTransaction({
      to,
      value: parseEther(valueEth),
      nonce
    });

    console.log(`Sent tx ${tx.hash} with nonce ${nonce}`);
    return tx;
  }

  // Reset local nonce tracker (e.g., after errors)
  resetNonce() {
    this.localNonce = null;
  }
}

2. Stuck Transaction Detector

Detect and report stuck transactions by comparing nonces:

JavaScript
async function detectStuckTransactions(provider, address) {
  const confirmedNonce = await provider.getTransactionCount(address, 'latest');
  const pendingNonce = await provider.getTransactionCount(address, 'pending');

  const pendingCount = pendingNonce - confirmedNonce;

  if (pendingCount === 0) {
    console.log('No pending transactions');
    return { status: 'clear', pendingCount: 0 };
  }

  console.log(`${pendingCount} pending transaction(s) detected`);
  console.log(`Confirmed nonce: ${confirmedNonce}`);
  console.log(`Pending nonce: ${pendingNonce}`);
  console.log(`Stuck nonces: ${confirmedNonce} to ${pendingNonce - 1}`);

  return {
    status: 'stuck',
    pendingCount,
    confirmedNonce,
    pendingNonce,
    stuckNonces: Array.from(
      { length: pendingCount },
      (_, i) => confirmedNonce + i
    )
  };
}

// Usage
const result = await detectStuckTransactions(provider, '0x5F0b1a82749cb4E2278EC87F8BF6B618dC71a8bf');
if (result.status === 'stuck') {
  console.log('Consider replacing transactions at nonces:', result.stuckNonces);
}

3. Batch Transaction Submitter

Submit multiple transactions in sequence with correct nonce ordering:

JavaScript
async function sendBatchTransactions(wallet, transactions) {
  const startNonce = await provider.getTransactionCount(
    wallet.address, 'pending'
  );

  console.log(`Sending ${transactions.length} transactions starting at nonce ${startNonce}`);

  const receipts = [];
  for (let i = 0; i < transactions.length; i++) {
    const nonce = startNonce + i;
    const tx = await wallet.sendTransaction({
      ...transactions[i],
      nonce
    });

    console.log(`Tx ${i + 1}/${transactions.length} sent: ${tx.hash} (nonce: ${nonce})`);
    receipts.push(tx);
  }

  // Wait for all to confirm
  const confirmed = await Promise.all(
    receipts.map(tx => tx.wait())
  );

  console.log(`All ${confirmed.length} transactions confirmed`);
  return confirmed;
}

// Usage
const transactions = [
  { to: '0xRecipient1...', value: parseEther('0.1') },
  { to: '0xRecipient2...', value: parseEther('0.2') },
  { to: '0xRecipient3...', value: parseEther('0.05') }
];

await sendBatchTransactions(wallet, transactions);

Best Practices

  • Always use pending block tag when fetching the nonce for a new transaction to avoid nonce collisions
  • Track nonces locally with a monotonic counter that syncs with the pending nonce from the network on reset
  • If pending nonce equals latest nonce, no stuck transactions exist -- the account is clean
  • For high-throughput applications (multiple transactions per second), implement a local nonce manager with retry logic
  • The nonce starts at 0 for new accounts and increments by 1 for each confirmed outbound transaction

Error Handling

Common errors and solutions:

Error CodeDescriptionSolution
-32602Invalid paramsVerify the address is a valid 20-byte hex string and the block parameter is valid
-32603Internal errorRetry with exponential backoff
-32000Block not foundThe requested block may be pruned - use latest or pending
-32005Rate limit exceededImplement caching for nonce lookups
JavaScript
async function safeGetNonce(provider, address, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await provider.getTransactionCount(address, 'pending');
    } catch (error) {
      if (error.code === -32005) {
        await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
        continue;
      }
      if (i === maxRetries - 1) throw error;
      await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
    }
  }
}

Related Methods

  • eth_sendRawTransaction - Send a signed transaction to the network
  • eth_getBalance - Get the ETH balance of an address
  • eth_getTransactionByHash - Get transaction details by hash
  • eth_getTransactionReceipt - Get the receipt of a confirmed transaction

eth_getStorageAt

Read the value from a storage slot at a given contract address on Zetachain. Essential for reading contract state directly, proxy implementation verification, and storage layout analysis.

eth_accounts

Returns a list of addresses owned by the client on Zetachain. Typically returns an empty array on public RPC endpoints.

On this page

When to Use This MethodCode ExamplesCommon Use Cases1. Safe Transaction Sender with Nonce Management2. Stuck Transaction Detector3. Batch Transaction SubmitterBest PracticesError HandlingRelated Methods