Web3auth not initialized yet

When asking for help in this category, please make sure to provide the following details:

  • SDK Version: v7.1.0
  • Platform: Reactjs

@vjgee I am getting this error very frequently after connecting wallet

Hey @psaini.php

What error are you getting?

I have implemented following conditions

if (!web3auth?.provider) {
alert(“provider not initialized yet”);
return;
}

Wallet is already connected but still getting web3auth.provider false.
@shahbaz

Hi @shahbaz sometimes, when I click on the connect wallet button, the following model will open and never close.

Hey @psaini.php

Could you kindly provide me with the code for initializing and logging in with web3auth?

useEffect(() => {
    const init = async () => {
      try {
        const web3auth = new Web3Auth({
          clientId,
          chainConfig: flareConfig,
          web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
          // uiConfig refers to the whitelabeling options, which is available only on Growth Plan and above
          // Please remove this parameter if you're on the Base Plan
          uiConfig: {
            appName: "W3A",
            theme: {
              primary: "blue",
            },
            mode: "auto",
            logoLight: "https://web3auth.io/images/web3auth-logo.svg",
            logoDark: "https://web3auth.io/images/web3auth-logo---Dark.svg",
            defaultLanguage: "en", // en, de, ja, ko, zh, es, fr, pt, nl
            loginGridCol: 3,
            primaryButton: "externalLogin", // "externalLogin" | "socialLogin" | "emailLogin"
          },
        });

        

        // adding metamask adapter
        const metamaskAdapter = new MetamaskAdapter({
          clientId,
          sessionTime: 3600, // 1 hour in seconds
          web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
          chainConfig: flareConfig,
        });
        // we can change the above settings using this function
        metamaskAdapter.setAdapterSettings({
          sessionTime: 86400, // 1 day in seconds
          chainConfig: flareConfig,
          web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
        });

        // it will add/update  the metamask adapter in to web3auth class
        web3auth.configureAdapter(metamaskAdapter);

        setWeb3auth(web3auth);

        await web3auth.initModal({
          modalConfig: {
            [WALLET_ADAPTERS.OPENLOGIN]: {
              label: "openlogin",
              loginMethods: {
                // Disable facebook and reddit
                facebook: {
                  name: "facebook",
                  showOnModal: false,
                },
                reddit: {
                  name: "reddit",
                  showOnModal: false,
                },
                google: {
                  name: "google",
                  showOnModal: false,
                },
                discord: {
                  name: "discord",
                  showOnModal: false,
                },
                twitch: {
                  name: "twitch",
                  showOnModal: false,
                },
                apple: {
                  name: "apple",
                  showOnModal: false,
                },
                line: {
                  name: "line",
                  showOnModal: false,
                },
                github: {
                  name: "github",
                  showOnModal: false,
                },
                kakao: {
                  name: "kakao",
                  showOnModal: false,
                },
                linkedin: {
                  name: "linkedin",
                  showOnModal: false,
                },
                twitter: {
                  name: "twitter",
                  showOnModal: false,
                },
                weibo: {
                  name: "weibo",
                  showOnModal: false,
                },
                wechat: {
                  name: "wechat",
                  showOnModal: false,
                },
                sms_passwordless: {
                  name: "sms_passwordless",
                  showOnModal: false,
                },
              },
            }, //Disable Torus Plugin
            [WALLET_ADAPTERS.TORUS_EVM]: {
              label: "TORUS_EVM",
              showOnModal: false,
            },
            [WALLET_ADAPTERS.WALLET_CONNECT_V2]: {
              label: "WALLET_CONNECT_V2",
              showOnModal: false,
            },
          },
        });

        if (web3auth.connected) {
          setLoggedIn(true);
        }
      } catch (error) {
        console.log("wallet--init--catch", error);
      }
    };

    init();
  }, []);

const web3Login = async () => {
    if (!web3auth) {
      alert("web3auth not initialized yet");
      return;
    }
    await web3auth.connect();
    setLoggedIn(true);
  };

@shahbaz

Why are these all set as false? Also, which login methods are you using?

I am using email/otp. and external wallet only @shahbaz

Hi @shahbaz any update on this

@psaini.php I will follow up on this and get back to you with an update.

please look at this image @vjgee @shahbaz
sometimes it is showing wallet is not connected when I click on that it will open like this . We have to refresh the browser to connect again

Hi @vjgee @shahbaz will you guys help me on this… its very urgent.

@psaini.php Can you share your package.json file

@vjgee
{
“name”: “demo”,
“private”: true,
“version”: “0.0.0”,
“type”: “module”,
“scripts”: {
“dev”: “vite”,
“build”: “vite build”,
“preview”: “vite preview”,
“prepare”: “husky install”
},
“dependencies”: {
@tanstack/react-query”: “^4.28.0”,
@tawk.to/tawk-messenger-react”: “2.0.2”,
@walletconnect/sign-client”: “^2.10.6”,
@web3auth/base”: “^7.1.0”,
@web3auth/modal”: “^7.1.1”,
@web3auth/torus-wallet-connector-plugin”: “^7.2.0”,
@web3auth/wallet-connect-v2-adapter”: “^7.3.1”,
“axios”: “^1.3.4”,
“daisyui”: “^2.51.3”,
“dateformat”: “5.0.3”,
“jwt-decode”: “3.1.2”,
“react”: “^18.2.0”,
“react-dom”: “^18.2.0”,
“react-ga”: “3.3.1”,
“react-icons”: “^4.8.0”,
“react-intl-tel-input”: “^8.2.0”,
“react-query”: “3.39.3”,
“react-router-dom”: “^6.8.2”,
“react-scroll”: “1.8.9”,
“react-toastify”: “9.1.2”,
“react-typed”: “1.2.0”,
“react-use”: “^17.4.0”,
“swiper”: “9.3.1”,
“web3”: “^1.10.0”
},
“devDependencies”: {
@types/react”: “^18.0.27”,
@types/react-dom”: “^18.0.10”,
@vitejs/plugin-react”: “^3.1.0”,
“autoprefixer”: “^10.4.14”,
“buffer”: “^6.0.3”,
“empty-module”: “^0.0.2”,
“husky”: “^8.0.3”,
“postcss”: “^8.4.21”,
“process”: “^0.11.10”,
“tailwindcss”: “^3.2.7”,
“vite”: “^4.1.0”
},
“overrides”: {
“react”: “$react”,
“react-dom”: “$react-dom”
}
}

similar issue was raised by someone else a year ago but still unresolved

@psaini.php Are you on Growth plan? I see you are using the uiconfig parameter.

not sure… may be basic one @vjgee

how uiconfig parameter effect it?

Please read this from the code you shared.

I got it … but how it relates to above issue that I have mentioned…

You are using Sapphire Mainnet, for which you need to be on a Growth plan. You need to confirm first what plan are you on to explain further.