I have to send multiple signed transactions and from a specific account with nonce via web3.eth.getTransactionCount. Because the call may come parallel, I either get

replacement transaction underpriced


Transaction was not mined within 50 blocks, please make sure your transaction was properly send.

What is the best way to calculate nonce and make every transaction unique?

I am using web3

1 Answer 1


I had a similar issue and used a global variable to remember the last nonce that was used. If the nonce you get from web3.eth.getTransactionCount is lower than that you can adjust the nonce accordingly. In code, it looks somehow like this:

var curnonce = web3.eth.getTransactionCount(account);
while (curnonce <= lastnonce) curnonce++;
lastnonce = curnonce;

Works fine and very reliable in my scenario.

  • yes, can work for single account, but if we have to use multiple account then we have to maintain a map. Commented Nov 15, 2017 at 12:24
  • that's right, since the nonce is account specific.
    – gisdev_p
    Commented Nov 15, 2017 at 14:52
  • somehow, if a transaction is not mined the upcomming transaction fails, not sure ho to resolve it, even not sure why the transaction is not mined Commented Feb 8, 2018 at 9:58
  • Which error message do you get when the upcoming transaction fails?
    – gisdev_p
    Commented Feb 8, 2018 at 23:31
  • no error but transaction is not mined, I send 10 transactions in a go with nonce increased 1 by 1 Commented Feb 15, 2018 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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