0

I created a site using web3.ys with some features, without react and node. How can I make it so that when entering from a mobile device and when clicking on the button, the user is transferred to the mobile metamask and immediately opens the browser with my site?

1 Answer 1

0

Here is what I use:

export function connectMetaMask(chainId) {
  if (!window.ethereum && isMobile()) connectMetamaskMobile();
  else return metaMaskConnector.activate(chainId);
}

export const connectMetamaskMobile = () => {
  const dappUrl = window.location.href.split("//")[1].split("/")[0];
  const metamaskAppDeepLink = "https://metamask.app.link/dapp/" + dappUrl;
  window.open(metamaskAppDeepLink, "_self");
};

This is described in the MetaMask Docs. I'm using this together with web3-react, however you only need the connectMetaMaskMobile part. Check this out if you want more info on detecting mobile browsers.

7
  • Im dont understund, how it integrate in my site:v
    – Cerberus
    Commented Jun 9, 2022 at 11:06
  • The code is not very complex, add in the function connectMetaMaskMobile somewhere and when a user clicks on a button, execute that function..
    – phaze
    Commented Jun 9, 2022 at 11:10
  • <button onclick="functionToExecute(connectMetaMaskMobile)">Click</button> Right?
    – Cerberus
    Commented Jun 9, 2022 at 11:16
  • more like: <button onclick="connectMetaMaskMobile()">Click</button>. When using normal html with js, you also take out the 'export' keyword.
    – phaze
    Commented Jun 9, 2022 at 11:18
  • Thank u:) Sorry for my bad knowledges)
    – Cerberus
    Commented Jun 9, 2022 at 11:19

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.