What is Nonce?
How it works
In proof-of-work blockchains like Bitcoin, the nonce is a 32-bit field in the block header. Miners repeatedly change the nonce and hash the header until they produce a hash below the target difficulty. This brute-force process secures the network by requiring computational work. When a valid nonce is found, the block is broadcast and added to the chain. The nonce is then consumed and cannot be reused for another block at the same height.
On smart contract platforms like Ethereum, the nonce is an account-specific counter tied to every externally owned account. It starts at zero and increments by one for each transaction sent. This sequential numbering prevents replay attacks: the same signed transaction cannot be executed twice because nodes check that the nonce matches the sender's current state. Nonces also enforce transaction ordering from a single account. If a transaction has a gap in nonce, it will be queued until the missing nonce is processed.
Ethereum's EIP-155 introduced a chain ID as part of the signing process to further protect against replay attacks across different networks (e.g., mainnet and testnet). While not strictly a nonce, it works alongside the transaction nonce. Additionally, in ERC-20 token approvals, a nonce is sometimes used in the permit function (EIP-2612) to allow gasless approvals with a unique identifier, preventing signature reuse.
Why it matters
Nonces are fundamental to blockchain security and integrity. In proof-of-work, they enable trustless consensus by requiring real resource expenditure. In transaction systems, nonces prevent double-spending and replay attacks, ensuring that each action is unique and properly ordered. Without nonces, signed transactions could be repeated maliciously, and mining would lack the verifiable randomness needed for decentralized agreement. They also enable deterministic transaction ordering from a single account.
Real-world examples
Bitcoin miners iterate nonces from 0 to 4,294,967,295 to find a valid block hash. Ethereum uses a transaction nonce per account, starting at 0 and incremented with each send. EIP-155 adds a chain nonce (chain ID) to prevent cross-chain replay. Protocols like Uniswap use nonces in off-chain permit signatures for token approvals.
FAQ
What happens if a transaction nonce is reused?
If a transaction with a previously used nonce is broadcast, it will be rejected by the network because the account's nonce has already advanced. This prevents replay of old transactions.
How does a mining nonce differ from a transaction nonce?
A mining nonce is a block-level counter changed by miners to find a valid hash. A transaction nonce is an account-level counter that ensures transaction uniqueness and order.
Can a nonce be skipped or left unused?
If a transaction with a higher nonce is broadcast before the preceding nonce, it will be held in a queue until the missing nonce transaction is confirmed. This can delay transaction processing.
Related terms
Go deeper
Browse the complete crypto glossary to explore related terms and concepts.
Browse Glossary