4

I have this code, which works:

MyToken.airdrop(wallets,amounts,{
  gas: 1267051,
  gasPrice: 2000000000,
},function(err,tx){
  console.log('err is %s',err)
  console.log('tx is %s',tx)
  callback(err,tx)
})

Now Let's say I want to control the nonce myself (reason here) so I do:

MyToken.airdrop(wallets,amounts,{
  gas: 1267051,
  gasPrice: 2000000000,
  nonce: 432 // = web3.eth.getTransactionCount() + 1
},function(err,tx){
  console.log('err is %s',err)
  console.log('tx is %s',tx)
  callback(err,tx)
})

I get a tx hash as output, not an error, yet the transaction can't be found on the appropriate etherscan, it seems to never get sent to the network. Tried on Rinkeby, Ropsten, and Kovan.

What could be the problem with specifying nonce myself or the way I'm doing it?

Note: I'm using infura as the "node".

1 Answer 1

9

Apparently there's a nuance with the nonce... my error was I was setting the nonce to web3.eth.getTransactionCount() + 1, which left a gap between prior transaction nonce and next transaction nonce (nonces are 0 indexed, transactions are indexed from 1, that's the root of the error). It so appears that you are not allowed to increment the nonce by 2 and leave a gap. Must be sequential.

3
  • 8
    You are allowed to send a tx with a nonce too high, but it will not be mined before the gap is filled. And you have to trust the miners to keep the high-nonce-tx in their tx pool while you fill the gap. Jul 3, 2018 at 16:02
  • Good catch! didn't know of the discrepancy in indexing. Jul 3, 2018 at 18:06
  • would be great to see the working code in your answer.
    – Senju
    Dec 10, 2019 at 14:00

Your Answer

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

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