3

When creating raw transactions, do I have to increase the nonce always in increments of 1 or can I use any nonce as long as it has not been used before?

Are there any specific rules? Could I also go up and down, like transaction #5 gets nonce 17 and transaction #6 gets nonce 13?

Can I use any nonce as long as it is not previously been used?

q9f
  • 32,913
  • 47
  • 156
  • 395

1 Answers1

4

No, the nonce needs to equal the number of transactions sent from the address; so that also means no jumping around.

The account state comprises the following four fields: nonce: A scalar value equal to the number of transactions sent from this address

(Section 4.1 of Yellow Paper)

eth
  • 85,679
  • 53
  • 285
  • 406
  • 1
    Strictly monotonic increasing starting from 0. – murrekatt Aug 05 '16 at 07:39
  • On practice it seems that if you skip a number in nonces of your transactions they will never be taken from the mempool, waiting indefinitely for that skipped number. So, yeah, strictly monotonic increasing. – Klesun Oct 18 '22 at 21:32
  • @Klesun Yes. The transactions skipping a nonce are not valid transactions yet, so that's why no one will put them in a block, because doing so would make the block invalid, and no one would build on top of an invalid block. You probably see that once there's a transaction with the missing nonce, that transaction and others with subsequent nonce, could have a chance of all getting included into the same block. – eth Oct 20 '22 at 02:46