Skip to main content

eth_getTransactionCount

Retrieves the number of transactions sent from an account on the Base network. This method returns the account's nonce, which is essential for transaction ordering and preventing replay attacks. The nonce represents the count of confirmed transactions from the specified address.

Description​

The eth_getTransactionCount method is crucial for Base blockchain interaction as it provides the current transaction count (nonce) for any account. This value must be included in every transaction to ensure proper ordering and prevent duplicate transactions on the Base Layer 2 network.

Parameters​

ParameterTypeRequiredDescription
addressstringYesThe Ethereum address (20-byte hex string with 0x prefix) to get transaction count for
blockNumberstringYesBlock number as hex string, or block tag: "latest", "earliest", "pending", "safe", "finalized"

Block Parameter Options​

  • "latest" - Most recent confirmed block (recommended for confirmed count)
  • "pending" - Include pending transactions in mempool (use for next nonce)
  • "earliest" - Genesis block
  • "safe" - Latest safe head block
  • "finalized" - Latest finalized block
  • "0x..." - Specific block number in hex

Returns​

Type: string

Returns the transaction count as a hexadecimal string (e.g., "0x1c" = 28 transactions). This value represents:

  • For EOA (Externally Owned Accounts): Number of transactions sent
  • For Contract Accounts: Number of contracts created by this account

Use Cases​

  • Transaction Building: Get next nonce for new transactions
  • Wallet Management: Track account activity and transaction history
  • Nonce Management: Prevent transaction conflicts in DApps
  • Account Analysis: Determine if address is active or new
  • Batch Transactions: Sequence multiple transactions correctly

Code Examples​

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

# Get pending transaction count (includes mempool)
curl -X POST https://api-base-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"pending"
],
"id": 2
}'

Response Examples​

Latest Block Transaction Count​

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

Pending Transaction Count​

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

Important Notes​

Nonce Management​

  • Transaction Ordering: Each transaction must use the next sequential nonce
  • Pending vs Confirmed: Use "pending" to include mempool transactions when building new transactions
  • Failed Transactions: Failed transactions still consume the nonce and increment the count
  • Nonce Gaps: Transactions with gaps in nonce sequence will be held until earlier nonces are filled

Best Practices​

  • Always use "pending" when preparing new transactions to avoid nonce conflicts
  • Cache nonce values briefly but refresh for each new transaction batch
  • Handle nonce collisions by incrementing and retrying
  • Monitor both confirmed and pending counts for wallet applications

Base Network Specifics​

  • Base inherits Ethereum's nonce system as an Optimistic Rollup
  • L2 transaction finality is faster than Ethereum mainnet
  • Nonce management is crucial for Base DApp development
  • Consider batch transaction sequencing for gas optimization

Common Use Cases​

  1. Wallet Integration: Track user transaction history
  2. DApp Development: Sequence contract interactions
  3. Transaction Builders: Generate properly ordered transactions
  4. Account Analysis: Determine account activity levels
  5. Automated Systems: Manage nonce for bot transactions

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