Handling Nonces
Learn the best practices for handling nonces when building smart contract accounts on Abstract.
As outlined in the tranasction flow, a call to validateNonceUsage
is made to the NonceHolder system contract
before each transaction starts, in order to check whether the provided nonce
of a transaction has already been used or not.
The bootloader enforces that the nonce:
- Has not already been used before transaction validation begins.
- The nonce is used (typically incremented) during transaction validation.
Considering nonces in your smart contract account
As mentioned above, you must “use” the nonce in the validation step. To mark a nonce as used there are two options:
- Increment the
minNonce
: All nonces less thanminNonce
will become used. - Set a non-zero value under the nonce via
setValueUnderNonce
.
A convenience method, incrementMinNonceIfEquals
is exposed
from the NonceHolder
system contract. For example, inside of your smart contract wallet,
you can use it to increment the minNonce
of your account.
In order to use the NonceHolder system contract,
the isSystem
flag must be set to true
in the transaction, which can be done by using the SystemContractsCaller
library shown below.
Learn more about using system contracts.
Was this page helpful?