3

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".

5

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.

  • 4
    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. – Xavier Leprêtre B9lab Jul 3 '18 at 16:02
  • Good catch! didn't know of the discrepancy in indexing. – Meshugah Jul 3 '18 at 18:06

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.