Giter Club home page Giter Club logo

Comments (4)

mdtanrikulu avatar mdtanrikulu commented on July 17, 2024

Thank you! It's a good idea. But I am not sure If I can query Metamask without the extension popping up. When metamask is already connected, everything is fine but the otherwise the only way of getting this information is querying and querying will trigger the extension popup.

I would love to keep this issue open until finding if there is a way to do or not.

from use-metamask.

z384647062 avatar z384647062 commented on July 17, 2024

I'v looked up another project VGLoic/metamask-react , method eth_accounts may work.
In file metamask-provider.tsx:

async function synchronize(dispatch: (action: Action) => void) {
  const ethereum = (window as WindowInstanceWithEthereum).ethereum;
  const isMetaMaskAvailable = Boolean(ethereum) && ethereum.isMetaMask;
  if (!isMetaMaskAvailable) {
    dispatch({ type: "metaMaskUnavailable" });
    return;
  }

  const chainId: string = await ethereum.request({
    method: "eth_chainId",
  });

  const isUnlocked = await ethereum._metamask.isUnlocked();

  if (!isUnlocked) {
    dispatch({ type: "metaMaskLocked", payload: { chainId } });
    return;
  }

  // Using eth_accounts instead of eth_requestAccounts may not popup the extension.
  const accessibleAccounts: string[] = await ethereum.request({
    method: "eth_accounts",
  });

  if (accessibleAccounts.length === 0) {
    dispatch({ type: "metaMaskUnlocked", payload: { chainId } });
  } else {
    dispatch({
      type: "metaMaskConnected",
      payload: { accounts: accessibleAccounts, chainId },
    });
  }
}

from use-metamask.

mdtanrikulu avatar mdtanrikulu commented on July 17, 2024

Yes, I can confirm it works as intended. More detailed information about it is here.

Thanks for sharing with me @z384647062! I will implement it quite soon and ping here when it is ready.

from use-metamask.

mdtanrikulu avatar mdtanrikulu commented on July 17, 2024

It's out! Now you are able use silent getAccounts method with v1.2.2. Thanks for your contribution!

from use-metamask.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.