1

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

or

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

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. – Priyank Gupta Nov 15 '17 at 12:24
  • that's right, since the nonce is account specific. – gisdev_p Nov 15 '17 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 – Priyank Gupta Feb 8 '18 at 9:58
  • Which error message do you get when the upcoming transaction fails? – gisdev_p Feb 8 '18 at 23:31
  • no error but transaction is not mined, I send 10 transactions in a go with nonce increased 1 by 1 – Priyank Gupta Feb 15 '18 at 20:44

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.