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

web3 instantiation #1

Open
phoniks opened this issue Nov 6, 2017 · 3 comments
Open

web3 instantiation #1

phoniks opened this issue Nov 6, 2017 · 3 comments

Comments

@phoniks
Copy link

phoniks commented Nov 6, 2017

On the first run, I got the following error: Uncaught TypeError: _web2.default is not a constructor

After digging around a bit I was able to overcome it by replacing this:
web3 = new Web3(window.web3.currentProvider); on line 15 of /src/web3.js

with this:
web3 = new Web3.providers.QtSyncProvider();

As I'm new to dApps I'm still learning how web3 works, so I can't say I understand the effect of the change or whether it's a valid solution to this problem. Any ideas as to why the error occurs and how to properly fix it?

I suppose, more specifically, the purpose of this code seems to be to "Instantiate new web3 local instance" according to the notation. What is a "local" vs a "remote" instance of web3? I notice that the other provider available is the HttpProvider (as opposed to QtSyncProvider), so am I correct in assuming that Http = remote and QtSync = local?

@tshal0
Copy link

tshal0 commented Nov 6, 2017

The provider is the RPC service running that you hook into to execute transactions on an Ethereum blockchain.

If I run testrpc in my terminal (with testrpc installed of course), its default configuration would launch an RPC enabled Ethereum node with 10 local accounts at https://127.0.0.1:8545. That is my provider. I then tell my app to create a new Web3 instance, and give it the provider: https://127.0.0.1:8545 so that it can interact with this locally running private Ethereum node. All transactions are automatically mined (because it's testrpc and is designed for fast testing). The blockchain is completely local, and completely separate from the main Ethereum network. Anything you do with this provider does not affect the actual Ethereum network.

I honestly have no idea what QtSyncProvider is, or does. Google didn't help either.

It seems like it's another option provided by Web3 for instantiating a new provider? Are you running something like testrpc by any chance? Or maybe geth?

@phoniks
Copy link
Author

phoniks commented Nov 6, 2017

Okay, great - that all makes sense to me. Thanks for the explanation! I'd still be curious to know if anyone else could provide some insight on the QtSyncProvider though.

@leopoldjoy
Copy link
Owner

leopoldjoy commented Nov 9, 2017

@phoniks Are you using Parity locally? What line does the error reference? Did you follow all of the dev environment setup instructions?

If you would like to change the Web3 provider, please change line 8 of web3.js instead of line 15 because each page load only needs to create one Web3 instance (line 15 is for globally exporting the Web3 instance that already exists from line 8).

I am not familiar with QtSyncProvider, the only mentions of it that I can find are here in the old ethereum.js README that is three years out of date and these old web3.js issues that are also nearly three years old. It doesn't seem to be a currently supported feature.

My reference to "local" in my comment that says "instantiate new web3 local instance" is simply about the fact that the web3 variable is a local variable as opposed to a global variable (not blockchain related).

Any provider can be used to interact with a remote or local Ethereum blockchain. Line 8 is connecting to a local Ethereum blockchain and the provider is implicitly a WebsocketProvider, not an HttpProvider. Line 8 could alternatively be written as:

window.web3 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.1:8546'));

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

3 participants