Skip to main content

eth_getTransactionCount

Returns the total number of transactions sent from a specified account on the IoTeX network. This method provides the account's current nonce, which is fundamental for transaction sequencing and ensuring proper execution order on IoTeX's Layer 2 infrastructure.

Overview​

The eth_getTransactionCount method is essential for IoTeX blockchain development, providing the transaction count that serves as the nonce for new transactions. On IoTeX's Optimistic Rollup, proper nonce management ensures transaction ordering and prevents replay attacks while maintaining compatibility with Ethereum tooling.

Parameters​

ParameterTypeRequiredDescription
addressstringYesEthereum address (20-byte hex with 0x prefix) to query transaction count
blockNumberstringYesBlock reference: hex number, "latest", "earliest", "pending", "safe", "finalized"

Block Reference Options​

  • "latest" - Most recently mined block (recommended for confirmed count)
  • "pending" - Include pending transactions in mempool (use for next nonce)
  • "earliest" - Genesis block
  • "safe" - Latest safe block (L2 equivalent)
  • "finalized" - Latest finalized block on L1
  • "0x..." - Specific block number in hexadecimal format

Returns​

Type: string

Returns the transaction count as hexadecimal string (e.g., "0x2a" = 42 transactions). This represents:

  • EOA (Externally Owned Account): Total transactions sent from this address
  • Contract Account: Number of contract creations performed by this account

Use Cases​

  • Transaction Sequencing: Obtain next nonce for transaction construction
  • Wallet Applications: Display transaction history and account activity
  • DApp Integration: Manage transaction ordering for smart contract interactions
  • Account Monitoring: Track address activity and usage patterns
  • IoTeX Bridge Operations: Coordinate L1/L2 transaction sequencing

Implementation Examples​

# Get confirmed transaction count
curl -X POST https://api-iotex-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
"latest"
],
"id": 1
}'

# Get pending transaction count for next nonce
curl -X POST https://api-iotex-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
"pending"
],
"id": 2
}'

# Get transaction count at specific block
curl -X POST https://api-iotex-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
"0x1000000"
],
"id": 3
}'

Response Examples​

Confirmed Transaction Count​

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x2a"
}

Pending Transaction Count​

{
"jsonrpc": "2.0",
"id": 2,
"result": "0x2c"
}

Historical Block Count​

{
"jsonrpc": "2.0",
"id": 3,
"result": "0x15"
}

Key Considerations​

IoTeX-Specific Behavior​

  • L2 Finality: Transactions finalize faster than Ethereum mainnet
  • Sequencer Ordering: IoTeX sequencer processes transactions in order
  • L1/L2 Bridging: Cross-layer transactions may affect nonce sequencing
  • Gas Efficiency: Lower costs enable more frequent transactions

Nonce Management Best Practices​

  • Always Use Pending: Query "pending" state when building new transactions
  • Concurrent Handling: Implement nonce queuing for high-frequency applications
  • Error Recovery: Handle nonce gaps and resubmission scenarios
  • Monitoring: Track both confirmed and pending states for wallet applications

Transaction Sequencing​

  • Sequential Requirement: Nonces must be used in consecutive order
  • Gap Handling: Missing nonces block subsequent transactions
  • Reorg Resistance: IoTeX's finality model reduces reorganization risks
  • Batch Operations: Consider transaction batching for complex workflows

Integration Patterns​

  1. Wallet Development: Real-time nonce tracking for user transactions
  2. DeFi Protocols: Smart contract interaction sequencing
  3. Trading Bots: High-frequency transaction management
  4. Bridge Applications: Cross-layer transaction coordination
  5. Analytics Platforms: Account activity monitoring and reporting

Error Handling​

  • Invalid Address: Returns error for malformed addresses
  • Block Not Found: Historical queries may fail for pruned blocks
  • Network Issues: Implement retry logic with exponential backoff
  • Rate Limiting: Respect API rate limits for production applications

Need help? Contact our support team or check the IoTeX documentation.