You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oh, I think what might be going is that you're overwriting the global web3 with your local one in this scope.
This line is supposed to be checking to see if web3 is already defined in the global scope, but I think the line before that is breaking it.
I think it should probably be the following (feel free to change variable names):
let localWeb3:Web3;
if (typeof web3 !== 'undefined') {
localWeb3 = new Web3(web3.currentProvider);
} /** set the provider you want from Web3.providers */
else {
localWeb3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
Or, if you want to keep the same naming (this one might be better anyway, due to more explicit global scoping):
let web3:Web3;
if (typeof window.web3 !== 'undefined') {
web3 = new Web3(window.web3.currentProvider);
} /** set the provider you want from Web3.providers */
else {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
Basically, what I think is going on is that you're defining web3 in your local scope, then immediately checking to see if it exists (which it will, always), and trying to use the currentProvider from the web3 you just created (that doesn't have a provider yet)
Oh, I think what might be going is that you're overwriting the
global
web3 with your local one in this scope.This line is supposed to be checking to see if
web3
is already defined in the global scope, but I think the line before that is breaking it.I think it should probably be the following (feel free to change variable names):
Or, if you want to keep the same naming (this one might be better anyway, due to more explicit global scoping):
Basically, what I think is going on is that you're defining
web3
in your local scope, then immediately checking to see if it exists (which it will, always), and trying to use thecurrentProvider
from theweb3
you just created (that doesn't have a provider yet)