-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Issue calling setProvider #2786
Comments
I've couldn't reproduce this issue with the provided example. Could you reference the complete code as GitHub repository or gist file? |
So to give a slightly more verbose version of the above steps...so I start Ganache running at port 9545 and do the following:
It makes sense when looking at web3-core.cjs.js here. If a web3 instance does not have a provider it will throw when you try to set it because it calls |
Is it not also possible to initiate Web3 with a non-existing URL? const Web3 = require("web3");
const provider = new Web3.providers.HttpProvider("http://localhost:9545");
const web3 = new Web3('http://');
web3.setProvider(provider); |
Well yes, I assume that would work...but isn't that a bit janky? |
Yes, this is true. It is probably better if I update the setProvider method. I've checked the truffle-contract package and truffle does copy the methods from the Web3.js Contract class to a truffle related class. I think this could give some other problems. Is it possible for truffle to create a list and we could go through the list? |
Sure! What kind of a list would you like to compile exactly? Right now I am not too sure that I am completely aware of all of the problems that Truffle currently has with the newest versions of Web3. |
I also know the "strings to BN" change is going to be a big deal for Truffle since that is a breaking change and we just released a major version not too long ago. |
Hello! -web3@1.0.0-beta.55 Any news?? |
I think about a list where all the problems of truffle are listed would support the discussion :)
The EIP-1193 isn't finalized and the CustomProvider fallback was created with the given interface from truffle. Was there anything missing in the given interface? I think the biggest problem is that truffle does copy methods from the Web3 contract class to a custom truffle object with no relation to a Web3 API. Truffle could wrap these methods or it could use the ES6 proxy for providing the same truffle-contract API (adapter pattern).
Is it possible to have deeper insights? (code references etc.) Edit: Adapter Embark |
Let me talk with the Truffle team and see what information we can put together. To be honest I'm not sure how complete our knowledge is about what is currently incompatible with the latest versions of Web3. |
What do you suggest if I'm using Ganache as a provider?
|
Hello, I encountered the same issue. I'm only using Ganache as provider, running it on a server in my local network, and I was launching my node instance with this (not a Truffle project) : const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider("http://10.0.0.42:7545")); Then I got the following error : path/to/my/project/node_modules/web3-core/dist/web3-core.cjs.js:64
if (typeof this.currentProvider.clearSubscriptions !== 'undefined' && this.currentProvider.subscriptions.length > 0) {
^
TypeError: Cannot read property 'clearSubscriptions' of undefined
... But when I do it this way, it works : const Web3 = require('web3');
const ethprovider = new Web3.providers.HttpProvider("http://10.0.0.42:7545");
const web3 = new Web3('http://');
web3.setProvider(ethprovider); nodejs v10.15.3 |
This got fixed in the 2.x branch and 1.x doesn't have that issue. |
When creating a Web3 instance and then attempting to call
setProvider
with a valid provider, a TypeError occurs.Expected behavior
Calling
setProvider
should successfully set the provider without an error.Actual behavior
A TypeError occurs (see error logs below).
Steps to reproduce the behavior
Error Logs
Versions
The text was updated successfully, but these errors were encountered: