Nonce e ordinamento
Sequenziamento delle transazioni
Nonce e ordinamento è una lezione Web3 & DApp Development Fundamentals gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Web3 & DApp Development Fundamentals, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Web3 & DApp Development Fundamentals include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Why Order Matters
Imagine sending two transactions: first deposit, then withdraw. If they execute out of order, the withdrawal could fail.
The nonce guarantees your transactions run in the exact order you intend.
What Is an Account Nonce?
An account nonce is a counter tracking how many transactions an account has sent. It starts at 0 and increases by 1 with each confirmed transaction.
Note: this is different from the mining nonce in Proof of Work.
Account history:
tx with nonce 0 (1st tx)
tx with nonce 1 (2nd tx)
tx with nonce 2 (3rd tx)
next expected nonce: 3Enforcing Sequence
The network only executes a transaction whose nonce matches the account's next expected value.
A transaction with nonce 5 will not run until nonces 0 through 4 have been processed.
Preventing Replay Attacks
Because each nonce is used once, an attacker cannot replay (resubmit) an old signed transaction.
The network already processed that nonce, so the duplicate is rejected automatically.
Stuck Transactions
If a transaction with a given nonce gets stuck (too low a fee), all later nonces are blocked behind it.
Nothing can proceed until that gap is filled, because nonces must be sequential.
pending:
nonce 4 (stuck, low fee)
nonce 5 (waiting...)
nonce 6 (waiting...)
-> nonce 4 must clear firstReplacing a Transaction
To unstick things, you can replace a pending transaction by resubmitting it with the same nonce and a higher fee.
This is often called speed-up or cancel — validators take the higher-paying version.
Gaps in Nonces
A nonce gap happens when you submit nonce 7 while nonce 6 is missing.
The transaction sits unprocessed until the gap is filled, since the network requires a continuous sequence.
Ordering Within a Block
The nonce orders transactions from one account, but ordering between different accounts within a block is decided by the validator.
Validators typically order by fee, which is why ordering can be exploited (see MEV).
MEV and Ordering
Because validators choose transaction order, they can profit by reordering, inserting, or censoring transactions. This is called Maximal Extractable Value (MEV).
It shows that ordering is economically valuable, not just technical bookkeeping.
Checking the Next Nonce
Wallets query the network for the next nonce using eth_getTransactionCount.
This returns the count of confirmed transactions, which equals the next nonce to use.
count = eth_getTransactionCount(
myAddress, "pending")
// count is the next nonce to usePutting It Together
The account nonce sequences your transactions, prevents replays, and must be continuous.
Validators decide cross-account ordering, which introduces fee-based prioritization and MEV.
Quick Check
Test your nonce knowledge.
Recap: Nonces and Ordering
You learned that:
- The nonce counts an account's transactions and enforces order
- It prevents replay attacks
- A stuck low nonce blocks later ones until replaced
- Validators decide cross-account ordering, enabling MEV
Next course: EVM fundamentals.
Impara Web3 & DApp Development Fundamentals con un tutor IA — gratis
Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.
- Corsi
- 29
- Lezioni
- 105
Domande Frequenti
La lezione «Nonce e ordinamento» è gratuita?
Sì — il testo completo di «Nonce e ordinamento» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Web3 & DApp Development Fundamentals, passa a CoddyKit PRO. Il corso Web3 & DApp Development Fundamentals include 4 lezioni in totale.
Cosa imparerò in «Nonce e ordinamento»?
Sequenziamento delle transazioni Eserciti Web3 & DApp Development Fundamentals con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Web3 & DApp Development Fundamentals?
Non è richiesta alcuna esperienza precedente. Web3 & DApp Development Fundamentals su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Nonce e ordinamento»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Web3 & DApp Development Fundamentals?
Sì. Ogni lezione Web3 & DApp Development Fundamentals include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Che cos'è il gas
- Ciclo di vita di una transazione
- Limiti e commissioni del gas
- Nonce e ordinamento