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
    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
    Jun 9, 2022 at 11:10
  • <button onclick="functionToExecute(connectMetaMaskMobile)">Click</button> Right?
    – Cerberus
    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
    Jun 9, 2022 at 11:18
  • Thank u:) Sorry for my bad knowledges)
    – Cerberus
    Jun 9, 2022 at 11:19

Your Answer

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

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