Hi guys,
I am having an issue with the following JavaScript. I would like to switch the user’s network in MetaMask on page load. The error that I am receiving states “Uncaught Error: Missing web3 instance, make sure to call Moralis.enableWeb3() or Moralis.authenticate()”. As you can see, I am running the enableWeb3() function. Any help would be appreciated.
Moralis.enableWeb3();
const currentUser = Moralis.User.current();
if (currentUser.attributes.sessionToken) {
$('#connect').hide();
$('#disconnect').show();
const ethAddress = currentUser.get('ethAddress');
console.log("Wallet Address: " + ethAddress);
if (web3.currentProvider.chainId != "0x38")
{
Moralis.switchNetwork("0x38");
}
}
else {
$('#connect').show();
$('#disconnect').hide();
}
Thanks in advance