'What to do about "transaction nonce too high" errors in RSK?

I have a decentralised application deployed on RSK, and has been working for several months. Everything works correctly using the public node, however infrequently, we start getting a totally random error:

Unknown Error: { 
  "jsonrpc": "2.0", 
  "id": 2978041344968143, 
  "error": { 
    "code": -32010, 
    "message": "transaction nonce too high" 
  } 
}

There is no information about “too high” nonces but many threads about “too slow”. I’m using web3.Contract.method.send().



Solution 1:[1]

In Metamask, ensure you are on your dev/test account then:

1 click on the avatar circle top right 2 In the menu, choose Settings 3 Click Advanced 4 Scroll down a bit, make sure again you are on your testnet account, click Reset Account

Solution 2:[2]

There is a limit on the number transactions the same address can have on the transaction pool.

This limit is 4 for RSK, and is defined within TxValidatorNonceRangeValidator within the rskj code base:

BigInteger maxNumberOfTxsPerAddress = BigInteger.valueOf(4);

Note that Ethereum has a similar limit, but the limit that is configured in geth is 10. So if we have already sent 4 transactions, that have not been mined yet, and send a 5th transaction before the next block is mined, it will get an error that the nonce is too high. If a block was mined and it had let's say all 4 of the transactions, then we would be able to add up to 4 transactions for the next block.

Workarounds

(1) Send no more than 4 transactions from an address, until there is a new block.

(2) Aggregate all of the calls and then use a contract that executes them in a single go. An example of this is seen in RNS Batch Client ExecuteRegistrations.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nihi Gabriel
Solution 2 Alvaro