![](/img/trans.png)
[英]How to launch Chrome packaged app by clicking on a button in a html page
[英]How to detect,launch and connect to metamask mobile app by clicking on a button on the webapp like on opensea?
我實現了一個短代碼,它連接到 metamask 瀏覽器擴展並使用web3 和 reactjs顯示用戶帳戶,此代碼在使用桌面瀏覽器時運行良好,但是當我在移動瀏覽器上嘗試時, metamask 移動版本由於非- 移動瀏覽器中存在其擴展, opensea之類的網絡應用程序如何使用移動網絡瀏覽器上的按鈕打開 metamask 移動應用程序?
代碼 :
export const connectWallet = async () => {
if (window.ethereum) {
try {
const addressArray = await window.ethereum.request({
method: "eth_requestAccounts",
});
const obj = {
status: "👆🏽 Write a message in the text-field above.",
address: addressArray[0],
};
return obj;
} catch (err) {
return {
address: "",
status: "... " + err.message,
};
}
} else {
return {
address: "",
status: (
<span>
<p>
{" "}
{" "}
<a target="_blank" href={`https://metamask.io/download.html`}>
You must install Metamask, a virtual Ethereum wallet, in your
browser.
</a>
</p>
</span>
),
};
}
};
您可以通過從以下鏈接生成元掩碼應用程序的深層鏈接來做到這一點: https<\/a> :\/\/metamask.github.io\/metamask-deeplinks\/# 並通過分辨率或 userAgent 檢測設備。
// first detect if window.ethereum is there
// render app
// else
// detect if mobile device
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
// open the deeplink page
window.open("insert deeplink here")
} else {
// install metamask message
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.