All of sudden my application on testnet has stopped working due to low nonce error. No change in source code. My app connects to the network via infura. Any ideas what could be wrong here.

java.lang.RuntimeException: Error processing transaction request: nonce too low
57879         at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:67) ~[core-3.3.1.jar!/:na]
57880         at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:51) ~[core-3.3.1.jar!/:na]
57881         at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:83) ~[core-3.3.1.jar!/:na]
57882         at org.web3j.tx.Transfer.send(Transfer.java:65) ~[core-3.3.1.jar!/:na]
57883         at org.web3j.tx.Transfer.lambda$sendFunds$2(Transfer.java:97) ~[core-3.3.1.jar!/:na]
57884         at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30) ~[core-3.3.1.jar!/:na]
57885         at bitmovio.service.blockchain.manager.WalletManager.makeExternalPaymentForRecurringWithdrawl(WalletManager.java:1331) [classes!/:1.0-SNAPSHOT]
57886         at bitmovio.service.blockchain.manager.WalletManager.settleMonthlyRecurringWithdrawl(WalletManager.java:1162) [classes!/:1.0-SNAPSHOT]
57887         at bitmovio.service.blockchain.manager.WalletManager$$FastClassBySpringCGLIB$$76b35353.invoke(<generated>) [classes!/:1.0-SNAPSHOT]
57888         at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
57889         at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) [spring-aop-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
57890         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
57891         at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport

The nonce you are giving in the transaction has already been consumed for this address on a blockchain.

Each Ethereum address, has a nonce starting from zero and increased by one for each new transaction.

When you give the nonce when building the transaction it does not match one for the address in Ethereum blockchain itself.

The solution is to sync the nonce from the blockchain and always use the next free nonce when creating a transaction.

How this happens for you is unclear, as the question lacks any source code giving context what you try to do.

  • FastRawTransactionManager transactionManager = new FastRawTransactionManager(web3, credentials1, ChainId.NONE, transactionReceiptProcessor); BigInteger nonce = transactionManager.getCurrentNonce(); Transfer transfer = new Transfer(web3, transactionManager); transfer.sendFunds(toAddress, amount, Convert.Unit.ETHER, gasPrice, Transfer.GAS_LIMIT.multiply(new BigInteger("6"))); – hd312 Feb 26 at 14:37
  • above is my source in java using web3j. when I print the nonce, the value is always -1. this failure does not usually happen the first time. i run into this error from second transaction onwards. the same code has worked for several months on rinkeby testnet – hd312 Feb 26 at 14:40
  • 1
    I am not expert in web3j, but my guess is that FastRawTransactionManager is not connected to Ethereum node or there is some other reason it cannot get the proper nonce. You can always check the nonce manually on EtherScan. Maybe something has changed in your node setup? – Mikko Ohtamaa Feb 26 at 15:19

FastRawTransactionManager will initialize to the latest confirmed nonce. And will only increment the nonce when that instance send a new transaction.

If another instance send a new transaction the nonce will not be updated. You have to explicitely call resetNonce or setNonce.

It can also be the case your app is restarting and there was a pending transaction. And the nonce is initialized incorrectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.