Skip to main content

Nonces

If you create multiple transactions inside and/or outside of GasHawk, you might run into problems concerning the transactions nonces. Keep reading to learn how to avoid this.

What is a nonce?

Each address on ethereum adds a positive integer number to each transaction it creates. These are called nonces. They start at 0 and increase by 1 with each transaction. The evm enforces this behavior: any deviation leads to the transaction being rejected.

The rules are:

  1. nonces start at 0 for each wallet
  2. each nonce can only be used once
  3. the nonce has to increase by exactly 1 for each transaction

Examples for illegal nonces:

  • using the nonce 7 again, after it has already been used in a transaction
  • using nonce 3 when the highest nonce used so far is 1

Read more about nonces here.

How can this cause trouble?

Example 1: Transactions with and without GasHawk (or Diana and pizza)

Imagine this: you want to send 8 Dai to a Diana. They don't care if the funds arrive right now or in 3 hours, so you use GasHawk for this transaction. This is the 71st transaction from your wallet, it gets the nonce 70 and is handed to GasHawk. Well done!

Half an hour later you develop a craving for pizza and order from you favorite delivery service. You pay 12 Dai, using the same wallet as above. Because the delivery service wants to be paid right now, you decide not use GasHawk for this transaction. Yet another good decision!

But. Here is the problem. The 8-Dai-to-Diana with nonce 70 is still waiting for good gas prices inside GasHawk. You changed your from GasHawk to Mainnet in Metamask before submitting the 12-Dai-for-pizza transaction. So Infura (Metamasks service provider) scans the blockchain for the highest nonce of this wallet and finds 69, which leads to Metamask using nonce 70 for the 12-Dai-for-pizza transaction.

Now there are two transactions with nonce 70: 8-Dai-to-Diana and 12-Dai-for-pizza. Only one of them can be mined. In most cases it will be 12-Dai-for-pizza transaction, because Infura places it in the mempool right away while GasHawk is likely to wait for lower gas fees for a bit longer. But in any case, one of the two transactions is sure to be rejected by the mempool 😞.

Example 2: Multiple Transactions in GasHawk

Bob ../2022-09-10-13-00-33.pngo Alice and 30 Dai to Thomas. He uses GasHawk with a deadline of 6 hours, generates the 0.1-Eth-to-Alice transaction first and the 30-Dai-to-Thomas transaction afterwards. Both transactions are in the "Open Transactions" sections now:

Bob realizes he made a mistake and only included 0.01 Eth in the 0.1-Eth-to-Alice transaction. Obviously, he wants to correct his mistake by deleting the sill open transaction and recreating it correctly. Usually, Bob has several options with his transactions that can be accesses by clicking on the three dots in the upper right corner: ../2022-09-10-12-57-02.png

But somehow, the 0.1-Eth-to-Alice can not be deleted: ../2022-09-10-12-50-56.png

Why is that? Because if Bob deletes the 0.1-Eth-to-Alice transaction with nonce X, he also invalidates the 30-Dai-to-Thomas transaction with nonce X+1. We at GasHawk decided to let the user delete only the newest transaction. So Bob has to delete the 30-Dai-to-Thomas first and the 0.1-Eth-to-Alice second. Afterwards, he can recreate both, hopefully without mistakes.

Other user interface limitations like not being able to pause the 0.1-Eth-to-Alice transation while the 30-Dai-to-Thomas transaction is "Hunting for lower Gas price", and not being able to force-transmit any but the first transaction in the queue, are all related to the handling of nonces.

Why doesn't GasHawk just fix the nonce already?

We'd love to! But we can't. GasHawk receives signed transactions from your wallet. Them being signed means that any tampering with any part of the transaction data invalidates the signature, and thus the transaction, which would therefore be rejected by the mempool. Apart from the nonces this is great: Neither you nor we want GasHawk to be able to tamper transactions.

What can you do about it then?

Don't send transactions on the ethereum mainnet from an address that still has pending transactions in GasHawk