0

i try to follow github web3modal guide to con figure my wallet connect in javascript . pls help me on this issue. appreciate

https://github.com/Web3Modal/web3modal-vanilla-js-example

html

  <button id="connectBtn" class="mint-btn btn-s" onclick="connectWallet"><span id="connectContent">connect wallet</span></button>
          </div>

<script src="./js/main.js"></script>
<script src="lib/ethers-5.2.umd.min.js" type="application/javascript"></script>

<script src="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/web3modal"></script>
<script type="text/javascript" src="https://unpkg.com/evm-chains/lib/index.js"></script>
<script type="text/javascript" src="https://unpkg.com/@walletconnect/web3-provider"></script>

main.js

    async function connectWallet() {
    
      const instance = await web3Modal.connect();
      const provider = new ethers.providers.Web3Provider(instance);
      const signer = provider.getSigner();
     
    
      // const provider = new ethers.providers.Web3Provider(window.ethereum)
      const network = await provider.getNetwork()
      console.log('network: ', network.name);
    
      const providerOptions = {
        /* See Provider Options Section */
      };
      
      const web3Modal = new Web3Modal({
        network: "mainnet", // optional
        cacheProvider: true, // optional
        providerOptions // required
      });
}

Package.json

{
  "dependencies": {
    "web3modal": "^1.9.8"
  }
}

my purpose to have this wallet provider option to pop when click on "connect wallet" enter image description here

Below is error am encounter .

enter image description here

Updated Hi Sir, after chg still encounter same error.

enter image description here

1 Answer 1

0

Ok, I've tried your code and you're calling the connect method of web3Modal in const instance = await web3Modal.connect(); but you declare it some lines later in const web3Modal = new Web3Modal(options);. That's the reason why you're getting this error. I've found this repo in which the connection is made with the same packages you are using. I recommend you taking a look to it and if you keep with problems don't doubt in asking again ser :)

2
  • hi sit , pls refer to "updated" section. still enocunter same error .
    – brook18
    Jun 20 at 7:44
  • I've editted my comment, sorry for the delay Jun 20 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.