Introduction to Nonce in EVM Chains
A nonce (number used once) is a critical component in Ethereum Virtual Machine (EVM) transactions, ensuring each transaction from an address is processed sequentially. This guide explains how to query nonce values using OKX's Wallet API, including pending transactions in the mempool.
API Endpoint for Nonce Query
Path: GET https://web3.okx.com/api/v5/wallet/pre-transaction/nonce
Required Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
chainIndex | String | Yes | Unique chain identifier |
address | String | Yes | Wallet address to query |
Key Concepts
- Nonce: The next valid sequential number for a new transaction.
- PendingNonce: The first nonce not yet in the mempool (e.g., if nonces 11–12 are pending,
pendingNonceis 13).
Example Scenario
- Last Confirmed Nonce: 10
- Pending Transactions: Nonces 11 and 12
Result:
nonce: 11 (next to broadcast)pendingNonce: 13 (next available slot)
API Response Parameters
| Parameter | Type | Description |
|---|---|---|
nonce | String | Next valid nonce for broadcasting |
pendingNonce | String | Earliest nonce unused in the mempool |
Example Request
curl --location --request GET \
'https://web3.okx.com/api/v5/wallet/pre-transaction/nonce?chainIndex=1&address=0x1ucda' \
--header 'Content-Type: application/json' \
--header 'OK-ACCESS-KEY: YOUR_API_KEY' \
--header 'OK-ACCESS-SIGN: YOUR_SIGNATURE' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z'Example Response
{
"code": "0",
"data": [{
"nonce": "15",
"pendingNonce": "21"
}],
"msg": "success"
}Best Practices for Nonce Management
- Avoid Duplicates: Never reuse a nonce.
- Monitor Mempool: Check pending transactions to prevent gaps or stalls.
- Error Handling: Retry failed transactions with the same nonce if needed.
👉 Explore advanced EVM transaction strategies
FAQ
Q1: What happens if I skip a nonce?
A: Subsequent transactions will be stuck until the skipped nonce is processed.
Q2: How do I reset my nonce?
A: Nonces are sequential; the only way to "reset" is by exhausting all pending transactions.
Q3: Can I query nonces for multiple addresses at once?
A: No, the API requires a single address per request.
👉 Learn more about Wallet API rate limits
Conclusion
Understanding nonce management ensures smooth transaction broadcasting on EVM chains. Use OKX's Wallet API to track pending nonces and optimize your dApp’s performance.