[solved] Error using useChain and switchNetwork - ReactApp

I get this error while trying to use the switchNetwork to change my chain id
Missing web3 instance, make sure to call Moralis.enableWeb3() or Moralis.authenticate()

is there a proper way to do it in react assuming the following were available in my code

import { useChain } from “react-moralis”;

const { switchNetwork } = useChain();

I think that you have enableWeb3 hook in react


yes worked this way

import { useMoralis, useChain} from “react-moralis”;

const { Moralis, logout, user } = useMoralis();
const { switchNetwork } = useChain();

await Moralis.enableWeb3();
1 Like