1

Function web3.eth.sendTransaction can throw an error.

For example:

  • Transaction gas is too low
  • Transaction execution error

But can it possibly throw an error before emitting the transactionHash event?

I am pretty sure that the two errors above cannot possibly occur at this point.

Am I right?

What about other errors?

For example, what if there's a network problem, or an Ethereum-client problem?

Here is a coding example (taken directly from the docs), with the question embedded:

web3.eth.sendTransaction({
    from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe',
    to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
    value: '1000000000000000'
})
.on('transactionHash', function(hash){
    // Can it possibly throw an error before reaching here?
})
.on('receipt', function(receipt){
    ...
})
.on('confirmation', function(confirmationNumber, receipt){ ... })
.on('error', console.error); // If a out of gas error, the second parameter is the receipt.

Thank you!

1 Answer 1

1

Yes ofcourse, a lot of errors can occur before emitting of transactionHash event. Example being:

  • basic validations like invalid sender address, receiver address, amount , gas etc.
  • When amount one is trying to send is more than his balance

So basically there is a number of validations by the client before sending a transaction to the blockchain and failure of any such validaion will result into a failure of tx even before getting hash.

I read somewhere list of validations that happen before sending of tx. I'll try to fetch that. So all those cases may cause failure even before getting hash.

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.