Nonces y ordenación
Secuenciación de transacciones
Nonces y ordenación es una lección gratuita de Web3 & DApp Development Fundamentals en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Web3 & DApp Development Fundamentals, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Web3 & DApp Development Fundamentals incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Aprende Web3 & DApp Development Fundamentals con un tutor de IA — gratis
Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.
- Cursos
- 29
- Lecciones
- 105
Preguntas frecuentes
¿La lección «Nonces y ordenación» es gratis?
Sí — el texto completo de «Nonces y ordenación» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Web3 & DApp Development Fundamentals, actualiza a CoddyKit PRO. El curso de Web3 & DApp Development Fundamentals incluye 4 lecciones en total.
¿Qué aprenderé en «Nonces y ordenación»?
Secuenciación de transacciones Practicas Web3 & DApp Development Fundamentals con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Web3 & DApp Development Fundamentals?
No se requiere experiencia previa. Web3 & DApp Development Fundamentals en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Nonces y ordenación»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Web3 & DApp Development Fundamentals?
Sí. Cada lección de Web3 & DApp Development Fundamentals incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Qué es el gas
- Ciclo de vida de una transacción
- Límites y comisiones de gas
- Nonces y ordenación