web3modal icon indicating copy to clipboard operation
web3modal copied to clipboard

“Provider not set or invalid” error when connecting with other providers

Open greentriangles1 opened this issue 3 years ago • 2 comments

I can connect using MetaMask on desktop just fine, but when trying anything else (eg, using WalletConnect to connect with MetaMask on mobile), I get a "Uncaught (in promise) Error: Provider not set or invalid" error.

More specifically, if I log web3.eth, I get the following object:

Eth {_requestManager: RequestManager, givenProvider: null, providers: {…}, _provider: null, }

For some reason, givenProvider is null, even though the provider returned from web3Modal.connect() is defined properly.

Code:

  const [account, setAccount] = useState('');
  const [web3, setWeb3] = useState(new Web3(Web3.givenProvider));

  const providerOptions = {
    walletconnect: {
      package: WalletConnectProvider, // required
      options: {
        rpc: url
      }
    }
  };

  const web3Modal = new Web3Modal({
    network: "mainnet", 
    cacheProvider: true
    providerOptions // required
  });
    
  async function connectPrompt() {
    const provider = await web3Modal.connect();

    setWeb3(new Web3(provider))
    const firstAccount = await web3.eth.getAccounts().then(data=>data[0]);
    setAccount(firstAccount);
  }

Screenshot of the provider and web3.eth objects: https://i.stack.imgur.com/HLk3Y.png

greentriangles1 avatar Aug 21 '21 17:08 greentriangles1

Same issue. Did you find any solution to this?

whyyor avatar Mar 18 '22 08:03 whyyor

did anyone get passed this ? I have this issue with walletconnect

ghost avatar May 12 '22 17:05 ghost

With stable version 2.0.0 of Web3Modal now released, we are officially dropping support for version 1.x Due to this this issue/pr was marked for closing. It is highly recommended to upgrade as 2.x will be receiving further updates that will enable functionality for some of our newer sdks like auth and push as well as support for WalletConnect v2 (See this post about WalletConnect v1 being deprecated https://medium.com/walletconnect/walletconnect-v1-0-sunset-notice-and-migration-schedule-8af9d3720d2e)

If you need to continue using Web3Modal 1.x and require this feature/fix implemented, we suggest adding it via forking V1 branch.

xzilja avatar Jan 21 '23 15:01 xzilja