Provider invalid or not set

Im created react application. The Issue im facing atm is that when i connect metamask through wallet connect. Its starts giving me provider not set error.

for getting web3 im using this
const web3 = await Moralis.Web3.enable();

for auth wallet
const user = await Moralis.Web3.authenticate({
provider: “walletconnect”,
});
Its working perfect on pc when i close metamask extension this error agains pops up . Which means my walletConnect is not setting the provider correctly

You are using an outdated way to authenticate and to enable web3.

how to authenticate nowadays

const user = await Moralis.authenticate(options)

and how to enable web3

const web3 = await Moralis.enableWeb3({ provider: "walletconnect" });

but the library im using is moralis and it doesnt have .enableWeb3

you can update to a newer version of Moralis SDK if it doesn’t have .enableWeb3.
you can find out your current version by running console.log(Moralis.CoreManager.get("VERSION"))

After updating to new version to 0.0.109 its Moralis.Web3.enableWeb3 not Moralis.enableWeb3

No, it isn’t. Moralis.Web3 is outdated syntax. You need to use Moralis.enableWeb3 without Web3

Also i need to send web3 object for my wallet connect provider all over my app. Any Suggestions ?

you can add it on the window object and you will have access to it in your whole dapp

window.web3 = await Moralis.enableWeb3()
1 Like