I'm currently working on a DApp that involves sending transactions. I'm using BlockCypher to send the transactions since the API is fairly straight forward. One issue I'm finding is that when I run my API locally and call the send transaction method I receive the transaction hash and I'm able to check it on Etherscan and the transaction does goes ahead.
The next step of course is deploying the API and then testing it, when I do this and hit the API endpoint with the exact same parameters. I receive the following error: Error validating transaction: Account nonce 68 too far behind transaction 0xad50ba948fc3fe266fb19c4aa3f3a81928ff114b3fadf597a620ec86eada7cf0:
. It doesn't appear that the transaction in question even exists (from searching for it on Etherscan) and so it seems that my Nonce for this account is out of sync with what it should be. Is that even possible? And what is the way to overcome this issue?
As it turns out, what I've found out is that the account should have a nonce of over 200, and the function web3.eth.getTransactionCount(ADDR)
seems to only be returning 68.
Here is how I construct the transaction:
var count = web3.eth.getTransactionCount(FROM_ADDR);
var data = myContractInstance.transfer.getData(to, value, { from: FROM_ADDR });
var gasPrice = "2000000000";
var gasLimit = 90000;
var rawTransaction = {
"from": FROM_ADDR,
"nonce": web3.toHex(count),
"gasPrice": web3.toHex(gasPrice),
"gasLimit": web3.toHex(gasLimit),
"to": to,
"data": data,
"chainId": 0x01
};
Strangely, when I changed the address the transactions are correctly sending again on both my local machine and the server. I've left a email for BlockCypher to see if they are able to help with this.
Thanks in advance,