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
-
Address -
DATA
, 20 Bytes- Address to get transaction count for
-
Block Parameter -
QUANTITY|TAG
latest
- Latest blockearliest
- Genesis blockpending
- 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
- JavaScript
- Python
import { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('https://api-zetachain-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);
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-zetachain-mainnet.n.dwellir.com/YOUR_API_KEY'))
address = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8'
nonce = w3.eth.get_transaction_count(address)
print(f'Nonce: {nonce}')
Related Methods
- eth_sendRawTransaction - Send transaction
- eth_getBalance - Get balance