web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

Hash returned but not broadcasting

Open NormTheThird opened this issue 8 years ago • 10 comments

We are receiving a hash back from sendRawTransaction but the transaction is never broadcasting to the network or if it does it could take 24 hours. Is this normal? Should we be getting a hash back if it has not broadcasted yet?

nonce++;
var nonceHex = web3.toHex(nonce);
var valueAmount = web3.toHex(amounts[i] * tokenMultiplier);

data = contract.transfer.getData(addresses[i], valueAmount, {from: "0xd5c..."})
                    
var rawTx = {
    "from": "0xd5c...",
    "nonce": nonceHex,
    "gasPrice": gasPrice,
    "gasLimit": gasLimit,
     "to": contract.address,
     "value": "0x00",
      "data": data,
      "chainId": 0x01
}

var tx = new Tx(rawTx);
 tx.sign(privateKey);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction(`0x${serializedTx.toString('hex')}`, function (err, hash) {
    if (err)
        console.log(err);
    else
        console.log('Transaction hash: ' + hash);
}); 

Thanks

NormTheThird avatar Mar 08 '18 22:03 NormTheThird

Check if your nonce is too high?

jamboj avatar Mar 09 '18 14:03 jamboj

I have checked that and its correct. We also started with a new wallet to see if that would help so the nonce would start at the beginning and that did not work either. Its been 17 hours and it has not broadcasted yet.

NormTheThird avatar Mar 09 '18 15:03 NormTheThird

This is happening to me as well.

cj-zeiger avatar Apr 24 '18 22:04 cj-zeiger

This is happening to me as well.

kilmas avatar Sep 02 '18 11:09 kilmas

This is happening to me as well. :(

i-am-vivek avatar Sep 26 '18 07:09 i-am-vivek

@kilmas & @i-am-vivek could you provide a code example too?

nivida avatar Nov 28 '18 10:11 nivida

I can add some additional information.

When I first started working with Web3.js I was ignorant to a lot of how Ethereum transactions worked. What was happening was my transaction was being broadcast but the node I was broadcasting to was not adding the transaction in the transaction pool. This can happen for a number of reasons:

  • Transaction pool of the node is full and the gas price is too small to take a spot in the pool
  • Node is handling too many transactions and one gets dropped
  • Other consequences of the non-deterministic nature of the Ethereum network.

In summary, none of these is caused by a bug with Web3.js.

My solution was writing a more robust version of what I was trying to accomplish and to monitor gas prices closely so that my transactions were not under gassed.

I'm not ruling out a possible bug with Web3.js, but because the three things I listed above are much more likely to be the cause of this occurring, I think @nivida would need a very detailed example to even start working on this.

cj-zeiger avatar Nov 28 '18 20:11 cj-zeiger

@cj-zeiger Thanks!

nivida avatar Apr 16 '19 09:04 nivida

Hey, I don't know whether the problem was with my node which I had installed or web3. later I moved to ethers.js and got a free node from infura.io. And configured in ethers.js. it started working.

i-am-vivek avatar Apr 16 '19 11:04 i-am-vivek

@i-am-vivek It was a problem of the node. Hopefully, you're coming back to the Web3.js library ;) We have some cool new features like customizing of the transaction signing process, correct transaction confirmations, Realms implementation, Web3 Module API and way more. Check our documentation to get more details about :)

nivida avatar Apr 16 '19 12:04 nivida