Mcap -- BTC -- ETH -- SOL -- BNB -- XRP -- F&G -- View Market
Loading prices…

Nonce

A number used once. In Bitcoin, the value miners change to find a valid block hash. In Ethereum, the counter that prevents replay attacks on transactions.

Cryptography 4 min read

A nonce is a number used once. The word shows up in two completely different contexts in crypto, and mixing them up is a common source of confusion, so it is worth separating them clearly.

Bitcoin Block Nonce

In Bitcoin mining, the nonce is a 32-bit field in the block header that miners increment (or randomise) while trying to find a valid block hash. The header contains the previous block hash, the Merkle root of the transactions, a timestamp, the difficulty target, and the nonce. Miners hash the header, check whether the result is below the target, and if not, they change the nonce and try again. With 2Β³Β² possible nonce values (about 4 billion) and enormous hash rates, miners exhaust the nonce space quickly and have to also vary other fields (the coinbase transaction, the timestamp, sometimes the extraNonce) to keep searching. Once they find a combination that produces a valid hash, that combination is the proof of work, and the nonce is part of the block header that gets broadcast.

The Bitcoin nonce is the textbook example of a “number used once” because each successful mined block has exactly one nonce that worked, and that nonce is unlikely to ever be hashed again in the same context. It is also a useful mental model for understanding why proof-of-work burns energy: the only way to find the right nonce is to try values until one happens to work, and trying values takes electricity.

Ethereum Transaction Nonce

In Ethereum, every account has a transaction nonce β€” a counter that increments by 1 with every transaction the account sends. Your first transaction has nonce 0, your second has nonce 1, your third has nonce 2, and so on. The nonce is included in every transaction and checked by the network: a transaction with the wrong nonce (too low or too high relative to the account’s current nonce state) will not be included in a block. This system serves two purposes. It enforces ordering, so you can send a sequence of transactions and know which one will execute first. It prevents replay attacks, because a signed transaction can only be executed once β€” replaying the same signed bytes after it has already been processed would fail the nonce check.

The Ethereum nonce is purely a counter, not a random number, and it has nothing to do with mining or hashing. It is just a way of saying “this is the Nth transaction from this address, in order” so that the network can process them correctly.

Where the Nonces Cause Problems

Stuck transactions are the most common issue an ordinary Ethereum user runs into. If you send a transaction with a gas price that turns out to be too low, it sits in the mempool without getting included. The nonce for that transaction is now “used” from your wallet’s perspective β€” any further transaction you send needs to use the next nonce, and those later transactions cannot execute until the earlier one does. You end up with a chain of pending transactions, all waiting on the first one. The fix is to replace-by-fee (RBF) the stuck transaction, sending a new transaction with the same nonce but a higher gas price. Most wallets support this under various names (“speed up”, “replace”).

Front-running your own transactions can also happen if you broadcast too many transactions at once and they get ordered unpredictably. If you need a specific order (approve, then swap), you have to wait for the first to confirm before sending the second, or you have to be careful about nonce management to ensure the order is enforced at the protocol level.

Importing the same account on multiple devices without coordinating between them can produce nonce conflicts, where both devices try to send a transaction using the same nonce and one of them fails. Hardware wallets and properly-designed wallet software handle this by reading the current nonce from the network before signing, but errors still happen occasionally, usually due to caching bugs.

For day-to-day use, you do not need to think about nonces β€” wallet software manages them automatically β€” but understanding what they are is useful when something goes wrong, because “nonce” is the word that will appear in the error message, and knowing what it means turns a confusing error into a fixable problem.