[英]How to connect to either Metamask for Coinbase wallet?
How do you specify connection with Coinbase Wallet and Metamask separately?如何分别指定与 Coinbase Wallet 和 Metamask 的连接?
Right now when using window.ethereum.enable() both the Metamask and Coinbase Wallet extensions popup.现在,当使用 window.ethereum.enable() 时,Metamask 和 Coinbase 钱包扩展弹出窗口。 I would like two separate buttons, one for Metamask and the other for Coinbase Wallet.我想要两个单独的按钮,一个用于 Metamask,另一个用于 Coinbase 钱包。
My code:我的代码:
const { createAlchemyWeb3 } = require("@alch/alchemy-web3");
const web3 = createAlchemyWeb3(alchemyKey);
export const connectWallet = async () => {
if (window.ethereum) { //check if Metamask is installed
try {
const address = await window.ethereum.enable(); //connect Metamask
}
}
})
From this discussion<\/a> , it seems like you may be able to use a different Metamask request method to force connection selection:从这个讨论中<\/a>,您似乎可以使用不同的 Metamask 请求方法来强制连接选择:
const connectWallet = async () => {
if (window.ethereum) { //check if Metamask is installed
try {
const address = await window.ethereum.request({
method: 'wallet_requestPermissions',
params: [{ eth_accounts: {}}]
});
} catch (error) {
console.log(error);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.