Web3 is null after updating SDK

Hi, please help!
I have this error after trying to update Moralis and Moralis-react to @latest version:

Hey it might be because we’re moving to etherjs as default :raised_hands: you can check out here to learn more about it Moralis JS SDK v1.0 (migration to Ethers.js)

1 Like

Thank you, @YosephKS
I have read the article, but it seems little confusing for my tiny brain :thinking:
Could you pls help me a bit more, I am still stuck with this…
in this MoralisDappProvider.js file, web3 is called from ‘useMoralis’ hook, and I dont know how to revise it ?

import { useEffect, useMemo, useState } from "react";
import { useMoralis } from "react-moralis";
import MoralisDappContext from "./context";
import React from "react";

function MoralisDappProvider({ children }) {
  const { web3, Moralis, user } = useMoralis();
  const [walletAddress, setWalletAddress] = useState();
  const [chainId, setChainId] = useState();
  useEffect(() => {
    Moralis.onChainChanged(function (chain) {
      setChainId(chain);
    });

    Moralis.onAccountsChanged(function (address) {
      setWalletAddress(address[0]);
    });
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);

  useEffect(() => setChainId(web3.givenProvider?.chainId));  
//Error: can not read properties of null (reading 'givenProvider')...
  useMemo(
    () =>
      setWalletAddress(
        web3.givenProvider?.selectedAddress || user?.get("ethAddress")
      ),
    [web3, user]
  );

  return (
    <MoralisDappContext.Provider value={{ walletAddress, chainId }}>
      {children}
    </MoralisDappContext.Provider>
  );
}

function useMoralisDapp() {
  const context = React.useContext(MoralisDappContext);
  if (context === undefined) {
    throw new Error("useMoralisDapp must be used within a MoralisDappProvider");
  }
  return context;
}

export { MoralisDappProvider, useMoralisDapp };

Any updates on this?? I am having the same issue

Which versions did you update to and which error(s) are you getting? In a React project, you should be using these versions or below:

[email protected] and [email protected]

I managed to update and solve this issue but, this error popped:

[ReferenceError: Can't find variable: localStorage]

Updated: i am now getting

[TypeError: WalletConnect is not a constructor (evaluating 'new Connector(options)')]

Can you post your package.json. Are you using a boilerplate like the OP was for this thread? You may need to use older versions of moralis and/or react-moralis.

What did you change in between getting the first error and the second error?

I am using the Etehreum react native boilerplate. My react packages are the next ones:

"moralis": "0.0.99",
"moralis-v1": "^1.11.0",
"react-moralis": "1.4.2",
"react-native": "~0.63.3",

Related thread - a previous version worked for that user.