ethjs / ethjs-provider-signer

A simple web3 standard provider that signs eth_sendTransaction payloads.
MIT License
71 stars 21 forks source link

Support for send() (synchronous version)? #2

Open sharkfisher opened 7 years ago

sharkfisher commented 7 years ago

ethjs-provider-signer/ethjs-provider-http

Issue Type

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

SilentCicero commented 7 years ago

@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.