ethjs-provider-signer icon indicating copy to clipboard operation
ethjs-provider-signer copied to clipboard

Support for send() (synchronous version)?

Open sharkfisher opened this issue 8 years ago • 1 comments

ethjs-provider-signer/ethjs-provider-http

Issue Type

  • [ ] Bug (https://github.com/ethjs/ethjs-provider-http/blob/master/.github/CONTRIBUTING.md#bug-reports)
  • [X] Feature (https://github.com/ethjs/ethjs-provider-http/blob/master/.github/CONTRIBUTING.md#feature-requests)

Description

web3.eth.sendTransaction() supports both a synchronous mode and an async mode. If a callback is not provided, this will be a synchronous call, with a return value being the transaction hash. If a callback is present, it's async. The default Web3.providers.HttpProvider supports both sync and async sends so if the above sendTransaction() is used with the default http provider, both work. ethjs-provider-signer and ethjs-provider-http however only support the async version (sendAsync()). When used as a drop-in replacement for HttpProvider in the sync version, an error is generated:

    var result = this.provider.send(payload);
                               ^
TypeError: this.provider.send is not a function

Can the sync version of send(payload) be added to both ethjs-provider-signer and ethjs-provider-http to make it a full drop-in replacement for HttpProvider, esp. since ethjs-provider-signer is the recommended replacement for HookedWeb3Provider? Efficiency aside, the sync version give people an option when async just can't cut it.

Steps to reproduce

const Web3 = require('web3');
const SignerProvider = require('ethjs-provider-signer');
const web3 = new Web3();
const signerProv = new SignerProvider(....);
const httpProv = new Web3.providers.HttpProvider("url");

web3.setProvider(httpProv);
let hash = web3.eth.sendTransaction({data: ..., from:...}); // works

web3.setProvider(signerProv);
hash = web3.eth.sendTransaction({data: ..., from: ...}); // does not work

Versions

  • Node/NPM: 7.7.1
  • Browser:

sharkfisher avatar Mar 23 '17 17:03 sharkfisher

@sharkfisher heyo, yes. We have a strict no-sync policy across all methods with ethjs. This is by choice. All methods are to be handled with proper callbacks or promises, so that errors are easier to handle.

See: https://github.com/ethjs/docs#web3js -- for more details.

SilentCicero avatar Mar 23 '17 18:03 SilentCicero