eth_getTransactionCount
Retrieves the number of transactions sent from an account on the Celo 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 Celo 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 Celo mobile-first blockchain network.
Parameters​
Parameter | Type | Required | Description |
---|---|---|---|
address | string | Yes | The Ethereum address (20-byte hex string with 0x prefix) to get transaction count for |
blockNumber | string | Yes | Block 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​
- cURL
- JavaScript
- Python
# Get latest confirmed transaction count
curl -X POST https://api-celo-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-celo-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"pending"
],
"id": 2
}'
// Get confirmed transaction count for wallet
async function getAccountNonce(address) {
const response = await fetch('https://api-celo-mainnet.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getTransactionCount',
params: [address, 'latest'],
id: 1
})
});
const data = await response.json();
return parseInt(data.result, 16); // Convert hex to decimal
}
// Get pending nonce for transaction building
async function getPendingNonce(address) {
const response = await fetch('https://api-celo-mainnet.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getTransactionCount',
params: [address, 'pending'],
id: 1
})
});
const data = await response.json();
return data.result; // Keep as hex for transaction
}
// Usage examples
const vitalikAddress = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
getAccountNonce(vitalikAddress).then(count => {
console.log(`Account has sent ${count} transactions`);
});
getPendingNonce(vitalikAddress).then(nonce => {
console.log(`Next transaction nonce: ${nonce}`);
});
import requests
import json
def get_transaction_count(address, block_tag="latest"):
"""Get transaction count for an address on Celo"""
url = "https://api-celo-mainnet.n.dwellir.com/YOUR_API_KEY"
payload = {
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [address, block_tag],
"id": 1
}
response = requests.post(url, json=payload)
result = response.json()
if 'error' in result:
raise Exception(f"RPC Error: {result['error']}")
return result['result']
def compare_nonces(address):
"""Compare confirmed vs pending transaction counts"""
confirmed = get_transaction_count(address, "latest")
pending = get_transaction_count(address, "pending")
confirmed_int = int(confirmed, 16)
pending_int = int(pending, 16)
return {
'confirmed_count': confirmed_int,
'pending_count': pending_int,
'pending_transactions': pending_int - confirmed_int,
'next_nonce': pending
}
# Example usage
vitalik_address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
# Get basic transaction count
count = get_transaction_count(vitalik_address)
print(f"Transaction count: {int(count, 16)}")
# Analyze account activity
nonce_info = compare_nonces(vitalik_address)
print(f"Confirmed transactions: {nonce_info['confirmed_count']}")
print(f"Pending transactions: {nonce_info['pending_transactions']}")
print(f"Next nonce to use: {nonce_info['next_nonce']}")
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
Celo Network Specifics​
- Celo is EVM-compatible and uses Ethereum's nonce system
- Celo transaction finality is faster with 5-second block times
- Nonce management is crucial for Celo DApp development
- Consider batch transaction sequencing for gas optimization
Common Use Cases​
- Wallet Integration: Track user transaction history
- DApp Development: Sequence contract interactions
- Transaction Builders: Generate properly ordered transactions
- Account Analysis: Determine account activity levels
- Automated Systems: Manage nonce for bot transactions
Need help? Contact our support team or check the Celo documentation.