0

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,

0

When you create a transaction with the full transaction object you can do different things including putting a different nonce. Just look at any pending transaction to see how it looks and build your transaction based on something like that:

[{
    blockHash: null,
    blockNumber: null,
    from: "0x010...",
    gas: 90000,
    gasPrice: 100000000000,
    hash: "0xe483aec6b05342eeedf3017314a2838180d66ee78a5ef21642c9f81b7b222dce",
    input: "0x",
    nonce: 269,
    r: "0x9927c6c3856b35ca4ef1155840a4dbd83b79daa5a581b58a23563880bd9838b1",
    s: "0x20bb0b13e8c87cff5677cfbb9c720b75104708e36cd08df5e844d5f1d359ebc5",
    to: "0x020...",
    transactionIndex: 0,
    v: "0xa95",
    value: 1000000000000000000
}]

So therefore you can try something like:

web3.eth.sendTransaction( { from : me , to : _to, value: web3.toWei(1), /*gas: 90000, gasPrice: 100000000000,*/ nonce: 269 } )

Alternatively you can try signing and sending a lot of transactions until you get what you need.

  • Hi Andrei, yes it does seem to be an issue on the BlockCypher end actually. I just changed the address that I was sending from and it worked ok. I also checked the nonce of the transaction before sending it and the nonce was over 200. Have sent them an email and hopefully it will get sorted. Will update the question. – SwimmingG Feb 23 '18 at 13:23

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.