Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendTransaction/sendSignedTransaction does not return tx hash on error #1216

Closed
mxmauro opened this issue Dec 7, 2017 · 2 comments
Closed
Assignees
Labels
Needs Clarification Requires additional input

Comments

@mxmauro
Copy link

mxmauro commented Dec 7, 2017

Scenario: Create a transaction that calls a contract's method that throws an error.

The sendTransaction/sendSignedTransaction call, internally ends in a call to provider's send/sendAsync. The result object in the callback contains the error message, like "VM exception.... revert" but the code builds an ErrorResponse object with only the message.

Although transaction hash is returned in result.result, it is discarded.

@gavrilyak
Copy link

gavrilyak commented May 23, 2018

Same problem here. I need transaction hash from sendTransaction but is seems the only way to get it is monkeypatching RequestManager.prototype.send like this

     if (!Jsonrpc.isValidResponse(result)) {
       return callback(errors.InvalidResponse(result));
     }

     if ('result' in result) {
       return callback(null, result.result);
     }

     if (result && result.error) {
       return callback(errors.ErrorResponse(result));
     }

It works, but monkeypatching is ugly and uses undocumented internals. It would be nice to have more straitforward way to get transaction hash from sendTransaction call.
New promievents API could allow to receive both 'transactionHash' and 'error' events and let the caller decide how to handle such situations.

@nivida nivida self-assigned this Aug 9, 2018
@nivida nivida added the Needs Clarification Requires additional input label Nov 29, 2018
@nivida
Copy link
Contributor

nivida commented Apr 16, 2019

You are able to get the transaction hash if you use the EventEmitter API instead of the Promise API from the PromiEvent we provide. Be aware that you can't combine the EventEmitter and the Promise.

web3.eth.sendTransaction(...).on('transactionHash', console.log).on('receipt', console.log)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Clarification Requires additional input
Projects
None yet
Development

No branches or pull requests

3 participants