A nonce is a number used once in cryptocurrency transactions to prevent double-spending and replay attacks.
What a Nonce Does
| Function | How It Works |
|---|
| Unique identifier | Each transaction has a unique nonce |
| Replay prevention | Same transaction can’t be submitted twice |
| Ordering | Transactions are processed in nonce order |
| Mining (PoW) | Miners increment nonce to find a valid hash |
Nonce in Bitcoin Mining
| Element | Value |
|---|
| Nonce range | 0 to 4,294,967,295 |
| Purpose | Find a hash below the target |
| How miners use it | Increment nonce → re-hash → check |
| Extra nonce | Coinbase transaction changes for more range |
Nonce in Ethereum Accounts
| Element | Value |
|---|
| Account nonce | Starts at 0, increments by 1 per transaction |
| Purpose | Prevent replay and ensure order |
| Gaps | If nonce 2 is pending, nonce 3 won’t process |
| Stuck transactions | Can’t send new txs until pending nonce clears |
Why Nonces Matter for Users
| Scenario | Problem |
|---|
| Stuck transaction | Nonce 5 is pending, can’t send nonce 6 |
| Replace transaction | Send same nonce with higher gas to override |
| Duplicate transaction | Same nonce prevents duplicate execution |
| Metamask nonce management | Custom nonce overrides default |
Managing Stuck Transactions
| Solution | How |
|---|
| Speed up | Resend with higher gas price (same nonce) |
| Cancel | Send 0 ETH to yourself with higher gas (same nonce) |
| Custom nonce | Manually set nonce to skip a stuck one |
Nonce in Ethereum Account Abstraction
With ERC-4337 (account abstraction), nonce management changes:
| Old (EOA) | New (ERC-4337) |
|---|
| Sequential nonce per account | Nonce can be custom |
| Stuck if nonce gap | Nonce gap doesn’t block |
| Hard to manage | Easier UX |
Developer View
| Task | How Nonce Is Used |
|---|
| Send transaction | Include nonce + 1 |
| Get pending nonce | eth_getTransactionCount |
| Build transaction | Sign with correct nonce |
| Handle failures | Track nonce on chain |
Bottom Line
A nonce is a counter that prevents replay attacks and ensures transaction ordering. In Bitcoin, miners use it for proof-of-work. In Ethereum, each account has a sequential nonce starting at 0. If a transaction gets stuck (nonce pending), you need to clear it before sending more transactions from that account. Use speed-up or cancel with higher gas.
This content is for educational purposes only. Not financial advice. Do your own research before investing.