Unable to open MetaMask wallet On retool

Hi, I am new to retool and I want to add a button that would open Metamask for wallet connection. I have import the web3js library but and window.ethereum is currently present in my browser. When I add the code below as run script to the button, metamask doesn't open

f (window.ethereum) {
     await window.ethereum.request({ method: "eth_requestAccounts" });
     window.web3 = new Web3(window.ethereum);
     const account = web3.eth.accounts;
     //Get the current MetaMask selected/active wallet
     const walletAddress = account.givenProvider.selectedAddress;
     console.log(`Wallet: ${walletAddress}`);
  
  } else {
   console.log("No wallet");
  }

AND

if (window.ethereum) {
  window.ethereum
    .request({ method: "eth_requestAccounts" })
    .then(() => {
      window.web3 = new Web3(window.ethereum);
      const account = web3.eth.accounts;
      // Get the current MetaMask selected/active wallet
      const walletAddress = account.givenProvider.selectedAddress;
      console.log(`Wallet: ${walletAddress}`);
    })
    .catch((error) => {
      console.error("Error requesting accounts:", error);
    });
} else {
  console.log("No wallet");
}

Hey @peter_munachi!

While many external libraries do work in Retool, it unfortunately isn't possible at the moment to import every npm package directly into Retool. As mentioned in our docs (here), you need to import a UMD build in order for it to work. The library you import also can't contain any require statements. That doc also covers exactly how you can import libraries though so it's definitely worth a look!

That being said, if you're open to doing a bit of extra work there is an interesting guide here on how you can develop and publish your own custom component for use within your Retool app. If you're interested in reading more about how to work with custom components in your app you can read these docs.

Also, Retool runs its Javascript in a sandboxed environment so you most likely won't have access to the parent window's methods.

Hope this helps a little, and please do let me know if you have any questions!