0Pricing
Web3 & DApp Development Fundamentals · Урок

Nonce и порядок

Выстраивание транзакций

«Nonce и порядок» — бесплатный урок Web3 & DApp Development Fundamentals на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Web3 & DApp Development Fundamentals, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Web3 & DApp Development Fundamentals содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

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: 3

Enforcing 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 first

Replacing 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 use

Putting 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.

Часто задаваемые вопросы

Урок «Nonce и порядок» бесплатный?

Да — полный текст урока «Nonce и порядок» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Web3 & DApp Development Fundamentals, подпишись на CoddyKit PRO. Курс Web3 & DApp Development Fundamentals содержит 4 уроков всего.

Чему я научусь в уроке «Nonce и порядок»?

Выстраивание транзакций Ты практикуешь Web3 & DApp Development Fundamentals с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Web3 & DApp Development Fundamentals?

Предыдущий опыт не требуется. Web3 & DApp Development Fundamentals на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 4 из 4.

Сколько времени занимает урок «Nonce и порядок»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Web3 & DApp Development Fundamentals?

Да. Каждый урок Web3 & DApp Development Fundamentals включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Что такое газ
  2. Жизненный цикл транзакции
  3. Лимиты газа и комиссии
  4. Nonce и порядок
← Назад к Web3 & DApp Development Fundamentals