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

TypeScript and Web3 constructor #2275

Closed
wnz99 opened this issue Jan 30, 2019 · 6 comments
Closed

TypeScript and Web3 constructor #2275

wnz99 opened this issue Jan 30, 2019 · 6 comments

Comments

@wnz99
Copy link

wnz99 commented Jan 30, 2019

Expected behavior

Initialize Web3 instance without passing an initial provider.

Actual behavior

I am trying to initialize Web3 in a TS project as follows:

const web3 = new Web3()
web3.setProvider(someProvider)

however the compiler outputs the following error:

An argument for 'provider' was not provided

Is this expected?

Steps to reproduce the behavior

const web3 = new Web3()
web3.setProvider(someProvider)

Error Logs

An argument for 'provider' was not provided

Versions

Web3 1.0.0-beta.41

@wnz99
Copy link
Author

wnz99 commented Jan 31, 2019

It looks like this is something that was introduced recently, [email protected] allows to initiate a Web3 instance without providing a provider.

Just for confirmation, should I consider this pattern no longer possible?

const web3 = new Web3()
web3.setProvider(someProvider)

const web3 = new Web3() is something that I came across quite a lot on available tutorials.

@andy0130tw
Copy link

andy0130tw commented Jan 31, 2019

Also encountered this issue when updating dependencies. I am worried about that If this breaking change is intentional, web3 instances cannot even be initialized in browsers without a injected web3 provider and requires much code for pre-1.0.0-beta.37 Dapps to adapt to.

For a quick workaround, pass a dummy (but invalid) URI that would be recognized as an HTTP RPC endpoint: new Web3('http://dummy')

@nivida
Copy link
Contributor

nivida commented Jan 31, 2019

@wnz99
Thanks for submitting this issue I'll fix this on Monday. I'm currently sick in the bed.

@nivida nivida added the Bug Addressing a bug label Jan 31, 2019
@wnz99
Copy link
Author

wnz99 commented Feb 1, 2019

sure, thank you.

@nivida
Copy link
Contributor

nivida commented Feb 4, 2019

@wnz99 or @andy0130tw can you explain me the exact use case for initiating a Web3 object without a provider?

@nivida
Copy link
Contributor

nivida commented Feb 26, 2019

I'm closing this issue because there was no answer from the creator.

@nivida nivida closed this as completed Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants