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

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

Open
1 of 2 tasks
sharkfisher opened this issue Mar 23, 2017 · 1 comment
Open
1 of 2 tasks

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

sharkfisher opened this issue Mar 23, 2017 · 1 comment

Comments

@sharkfisher
Copy link

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

  • Node/NPM: 7.7.1
  • Browser:
@SilentCicero
Copy link
Member

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

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

No branches or pull requests

2 participants