简体   繁体   English

Minting dapp 没有连接到手机上的 metamask 应用程序?

[英]Minting dapp does not Connecting to metamask app on mobile?

// constants
import Web3EthContract from "web3-eth-contract";
import Web3 from "web3";
// log
import { fetchData } from "../data/dataActions";

const connectRequest = () => {
  return {
    type: "CONNECTION_REQUEST",
  };
};

const connectSuccess = (payload) => {
  return {
    type: "CONNECTION_SUCCESS",
    payload: payload,
  };
};

const connectFailed = (payload) => {
  return {
    type: "CONNECTION_FAILED",
    payload: payload,
  };
};

const updateAccountRequest = (payload) => {
  return {
    type: "UPDATE_ACCOUNT",
    payload: payload,
  };
};

export const connect = () => {
  return async (dispatch) => {
    dispatch(connectRequest());
    const abiResponse = await fetch("/config/abi.json", {
      headers: {
        "Content-Type": "application/json",
        Accept: "application/json",
      },
    });
    const abi = await abiResponse.json();
    const configResponse = await fetch("/config/config.json", {
      headers: {
        "Content-Type": "application/json",
        Accept: "application/json",
      },
    });
    const CONFIG = await configResponse.json();
    const { ethereum } = window;
    const metamaskIsInstalled = ethereum && ethereum.isMetaMask;
    if (metamaskIsInstalled) {
      Web3EthContract.setProvider(ethereum);
      let web3 = new Web3(ethereum);
      try {
        const accounts = await ethereum.request({
          method: "eth_requestAccounts",
        });
        const networkId = await ethereum.request({
          method: "net_version",
        });
        if (networkId == CONFIG.NETWORK.ID) {
          const SmartContractObj = new Web3EthContract(
            abi,
            CONFIG.CONTRACT_ADDRESS
          );
          dispatch(
            connectSuccess({
              account: accounts[0],
              smartContract: SmartContractObj,
              web3: web3,
            })
          );
          // Add listeners start
          ethereum.on("accountsChanged", (accounts) => {
            dispatch(updateAccount(accounts[0]));
          });
          ethereum.on("chainChanged", () => {
            window.location.reload();
          });
          // Add listeners end
        } else {
          dispatch(connectFailed(`Change network to ${CONFIG.NETWORK.NAME}.`));
        }
      } catch (err) {
        dispatch(connectFailed("Something went wrong."));
      }
    } else {
      dispatch(connectFailed("Install Metamask."));
    }
  };
};

export const updateAccount = (account) => {
  return async (dispatch) => {
    dispatch(updateAccountRequest({ account: account }));
    dispatch(fetchData(account));
  };
};

Metamask extension is working fine in desktop but the issue is it not working on Mobile, it is not openning the metamask app, we dont know now how to solve this issue... If anyone here who can help will be great. Metamask 扩展在桌面上运行良好,但问题是它不能在移动设备上运行,它没有打开 metamask 应用程序,我们现在不知道如何解决这个问题......如果这里有人可以提供帮助,那就太好了。 We have a solution for this instead of using metamask, we want to use wallet connect integration, but we dont know how to do that too.我们有一个解决方案,而不是使用元掩码,我们想使用钱包连接集成,但我们也不知道该怎么做。 We have read the docs but we are too confuse in it....我们已经阅读了文档,但我们对此感到困惑......

On mobile connecting to wallets will not work in your normal chrome/safari browsers- apple or other mobile creators do not allow this you can only connect your wallet by using the browser in your metamask app on your phone.在移动设备上连接到钱包在您的普通 chrome/safari 浏览器中不起作用 - 苹果或其他移动创建者不允许这样做,您只能使用手机上 metamask 应用程序中的浏览器连接您的钱包。 ie. IE。

  1. navigate to metamask or whichever wallet you are using on your phone导航到 metamask 或您在手机上使用的任何钱包
  2. open the browser in that app在该应用程序中打开浏览器
  3. go to the website you need访问您需要的网站

I've found a way with deeplinking to work with Android and IOS from the browser, it solved my problem with opening MetaMask and redirect my app there ( or installing if its not installed )我找到了一种通过深度链接从浏览器中使用 Android 和 IOS 的方法,它解决了我打开 MetaMask 并将我的应用程序重定向到那里的问题(或者如果未安装则安装)

It's the complete code, you can find this part of code here:这是完整的代码,你可以在这里找到这部分代码:

https://github.com/EhsanParsania/MetaMask-React-sample/blob/main/src/components/MetaMaskInstallModal.js#L74 https://github.com/EhsanParsania/MetaMask-React-sample/blob/main/src/components/MetaMaskInstallModal.js#L74

or clone it and run to use and check all features:或克隆它并运行以使用并检查所有功能:

https://github.com/EhsanParsania/MetaMask-React-sample https://github.com/EhsanParsania/MetaMask-React-sample

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 metamask 移动浏览器中加载 dapp - Cant load dapp in metamask mobile browser 如何将 metamask 连接到 dapp? - How to connect metamask to dapp? 如何仅使用 dApp 限制 NFT 铸造 - How to restrict NFT minting using the dApp only 未安装元掩码时 React 应用程序不呈现 - React app does not render when metamask is not installed Metamask 移动应用程序在 iOS 模拟器错误:s PollingBlockTracker - Metamask mobile app in iOS Simulator error:s PollingBlockTracker MetaMask - RPC 错误:执行恢复,简单的 NFT 迷你 Dapp - MetaMask - RPC Error: execution reverted, Simple NFT Miniting Dapp "如何通过单击 webapp 上的按钮(如 opensea)来检测、启动和连接到 metamask 移动应用程序?" - How to detect,launch and connect to metamask mobile app by clicking on a button on the webapp like on opensea? 创建我的第一个移动应用程序并将其连接到数据库 - Creating my first Mobile App and connecting it to a database 如何单击 dapp/网站上的按钮,然后在 metamask 中确认交易? 然后每隔 xx 小时重复一次 - How to click button on dapp/website then confirm transaction in metamask? Then repeat every xx hour 使用 ReactJS 和 Javascript 中的 Metamask 连接用户以太坊帐户 - Connecting User Ethereum account with Metamask in ReactJS and Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM