ethjs / ethjs-contract

A simple contract object for the Ethereum RPC layer.
MIT License
20 stars 28 forks source link

Unhandled Promise #10

Open MicahZoltu opened 7 years ago

MicahZoltu commented 7 years ago

Issue Type

Description

The method called here returns a promise, but that promise is then dropped on the floor. When a failure occurs in the method, this results in an unhandled rejection error in node with a threat to crash the application in future versions of node. I have argued with the node/chrome maintainers at length that this is an incorrect behavior and inappropriate usage of promises but ultimately they decided to prefer making node "easy for bad programmers" rather than "powerful for advanced users" and it doesn't look like they plan on changing this. Because of this, all promises in a library should either return up the stack to the end-user or should be capped with a catch(...) before they are dropped.

Steps to reproduce

  1. Instantiate a contract.
  2. Call a method on that contract.
  3. Have your Ethereum node return a failure like {"id":6604108303907,"jsonrpc":"2.0","result":"0x6864f52eba193e1b7d1b2eafddcf454dfb1568d756c5782d40efbc8c8857efbc","error":{"message":"VM Exception while processing transaction: invalid opcode","code":-32000}}

In my case, the error I get back looks like (though the error specifics shouldn't matter):

Error: [ethjs-provider-http] Invalid JSON RPC response from provider
    host: http://localhost:64891
    response:  ""
    responseURL: undefined
    status: 0
    statusText: 

Versions

Peanut Gallery

This whole problem would go away if the library used promises all the way down rather than just faking it half of the time and using callbacks the other half of the time. Also, if written in ES2017 you could use async/await which would make the code much easier to read.

sathyamlokare commented 6 years ago

Error: [ethjs-provider-http] Invalid JSON RPC response from provider host: https://rinkeby.infura.io/ response: "" responseURL: undefined status: 405 statusText: Method Not Allowed

I get this error when I do a sendTransaction how do i solve this ?