0

I am using the web3modal

import { useWeb3Modal } from "@web3modal/react";

const foo = () => {
const { open, close } = useWeb3Modal();

async function connect_wallet() {
    try {
      await open(); // Open the web3modal provider selection modal
      console.log("web3 and provider")
      // provider
    } catch (error) {
      console.error("Error connecting to provider:", error);
    }
  
 }

return(
 <div>
  <button onClick={connect_wallet}>
    Connect Wallet
  </button>
 </div>
 )
}

so the web3modal pops up fine and gets connected, but how to grab the values of provider and web3 from it ?

1 Answers1

0

You can try in the following way.

import Web3Modal from "web3modal";
...
const provider = await web3Modal.connect();
console.log("Provider:", provider);
  • Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Jul 05 '23 at 00:51