🔢 eth_getTransactionCount - Base Chain
What This Method Does
The eth_getTransactionCount
method returns the number of transactions an address has sent on the Base blockchain. This number is also known as the "nonce" and is essential for creating new transactions.
💡 Why is this important? Every transaction from your address must use a unique, sequential nonce. Understanding transaction counts helps you create valid transactions and resolve stuck or pending transactions.
Parameters
Parameter | What to Provide |
---|---|
address | The wallet or contract address you want to check (42 characters, starts with "0x") |
blockNumber or Tag | Block number (in hex) or "latest", "earliest", or "pending" |
Note: Unlike Ethereum mainnet, Base chain does not support the "safe" and "finalized" tags.
What You'll Get Back
Transaction Count (Nonce)
- A hexadecimal number representing how many transactions this address has sent
Need RPC API keys?
Get 12.5M archival requests for free today.
How To Use It
POST https://base-mainnet.chainnodes.org/YOUR-API-KEY
Example Request
- HTTPS POST Request with a JSON RPC call in the body
- Replace YOUR-API-KEY with the API key from your Chainnodes.org Dashboard
- You can use a different supported network by replacing
base-mainnet
curl https://base-mainnet.chainnodes.org/YOUR-API-KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["0xad89a377e302791fb523ffb427f3f480cad3a72c", "latest"],"id":1}'
Example Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x2a"
}
In this example, the address has sent 42 transactions (0x2a in hexadecimal = 42 in decimal).
💡 Confusing?
Ask our experienced blockchain developers in Telegram
Common Use Cases
📤 Creating a New Transaction
When you send a transaction on Base, you need to include the correct nonce. This method tells you what nonce to use next.
// Get the current transaction count to use as nonce
const nonce = await eth.getTransactionCount('0xYourAddress', 'latest');
// Convert from hex to decimal if needed
const nonceDecimal = parseInt(nonce, 16);
// Use it in your transaction
const tx = {
from: '0xYourAddress',
to: '0xRecipientAddress',
value: '0x38D7EA4C68000', // 0.001 ETH in wei (hex)
nonce: nonce,
gasLimit: '0x5208', // 21000 in hex
maxFeePerGas: '0x59682F00', // Gas price in wei (hex)
chainId: '0x2105' // Base mainnet chain ID (8453 in decimal)
};
🔍 Check for Pending Transactions
Compare the transaction count at "latest" vs "pending" to see if your address has pending transactions.
// Get transaction count at the latest mined block
const latestCount = await eth.getTransactionCount('0xYourAddress', 'latest');
// Get transaction count including pending transactions
const pendingCount = await eth.getTransactionCount('0xYourAddress', 'pending');
// If they're different, you have pending transactions
const hasPendingTx = pendingCount > latestCount;
console.log(hasPendingTx ? "You have pending transactions" : "No pending transactions");
🛠️ Fix a Stuck Transaction
If you have a transaction stuck in the pending state, you can replace it by sending a new transaction with the same nonce but higher gas price.
// Get the nonce of your stuck transaction
const stuckTxNonce = '0x4'; // Example nonce in hex
// Create replacement transaction with same nonce but higher gas price
const replacementTx = {
from: '0xYourAddress',
to: '0xRecipientAddress',
value: '0x38D7EA4C68000', // Same value as original tx
nonce: stuckTxNonce, // Same nonce as stuck tx
gasLimit: '0x5208', // 21000 in hex
maxFeePerGas: '0x59682F00', // Higher gas price than original tx
chainId: '0x2105' // Base mainnet chain ID
};
Related Methods
- eth_sendRawTransaction - Send a signed transaction to the network
- eth_getTransactionByHash - Get details of a specific transaction
JSON-RPC Base API Documentation by CHAINNODES is based on Reth node client. Contact us if you are interested in specific methods that are only available on geth, besu, Nethermind or Erigon