1

I facing an issue while connecting in Metamask and Coinbase wallet. The issue is when I try to connect with Metamsk wallet it will open Coinbase extension. I think when both Metamask and Coinbase wallet was installed, Metamsk wallet was overridden by the Coinbase wallet. How to add separate wallet connect function for these Metamsk and Coinbase wallets.

these are the code sample now I'm using

export const GetWallet = async () => {
  if (typeof window.ethereum !== "undefined") {
    if (window.ethereum.isMetamask) {
      if (await window.ethereum._metamask.isUnlocked()) {
        return "metamask"; // Wallet is Metamask.
      } else {
        throw Error("not-unlocked");
      }
    }else{
      return "unknown"; // Wallet is Coinbase. Logic not complete here
    }
  } else {
    throw Error("non-ethereum"); 
  }
};

Unlock wallet function

  const unlockWallet = async () => {
        await window.ethereum.request({ method: 'eth_requestAccounts' });
        history.goBack();
    };

enter image description here

1 Answer 1

1

When using chrome extensions, you can access to each provider using window.ethereum.providers You can try console.log(window.ethereum.providers

Therefore, you can choose to connect Metamask or Coinbase Wallet with

let walletProvider = window.ethereum.providers.find((x) => x.isMetaMask) // isMetamask is part of the injected provider

... = new ethers.providers.Web3Provider(walletProvider)

same for Coinbase

let walletProvider = window.ethereum.providers.find((x) => x.isCoinbaseWallet) // isCoinbaseWallet is part of the injected provider

... = new ethers.providers.Web3Provider(walletProvider)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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