Web3.js: TypeScript and Web3 constructor

Created on 30 Jan 2019  路  6Comments  路  Source: ChainSafe/web3.js

Expected behavior

Initialize Web3 instance without passing an initial provider.

Actual behavior

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

javascript 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

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

Error Logs

An argument for 'provider' was not provided

Versions

Web3 1.0.0-beta.41

discussion

Most helpful comment

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.

All 6 comments

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.

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')

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

sure, thank you.

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mishell-trickster picture mishell-trickster  路  3Comments

3sGgpQ8H picture 3sGgpQ8H  路  3Comments

zamoore picture zamoore  路  3Comments

xpepermint picture xpepermint  路  3Comments

joeriexelmans picture joeriexelmans  路  3Comments