window.Ethereum.Providers不确定 - 允许用户选择MetAmask或Coinbase Wallet作为Web3提供商

发布于 2025-01-23 08:43:58 字数 884 浏览 2 评论 0原文

我们如何允许用户选择与Web3网站进行交互时使用的浏览器钱包 /提供商?这是针对基本的HTML / WordPress网站,不使用Typescript / React等

。 ,并在不使用Coinbase Wallet SDK的情况下具有用户签名消息和交易。”

https://docs.cloud.cloud.coinbase.com/wallet-sdk/文档/注射供应商

当前,我的集成与MetAmask无问题。但是,当尝试选择Coinbase钱包(浏览器扩展程序)作为我的提供商时,似乎没有一种方法可以这样做。

如果Window.Ethereum由Coinbase Wallet扩展设置,则假设有一个 window.Ethereum.providers 对象。然后,您可以浏览每个人,查找元掩体或共插基,然后将首选的提供商设置为:

metak与Coinbase Wallet冲突

但是,MetAmask似乎优先于此,并设置窗口。

我尝试在页面加载期间和之后加载 /查找Coinbase钱包提供商,但似乎不存在。同样,我假设MetAmask在Coinbase注入之前就将其设置为提供者。

有没有办法让用户设置使用基本Web3 JS使用的提供商 /钱包?

How do we allow users to choose which browser wallet / provider they use when interacting with web3 websites? This is for basic HTML / WordPress websites not using TypeScript / React, etc.

According to Coinbase Docs, the Coinbase Wallet SDK is not needed: "You can use this provider in your dapp to request users' Ethereum accounts, read on-chain data, and have the user sign messages and transactions, without using the Coinbase Wallet SDK."

https://docs.cloud.coinbase.com/wallet-sdk/docs/injected-provider

Currently, my integration works with MetaMask without issue. However, when trying to choose the Coinbase Wallet (browser extension) as my provider, there doesn't seem to be a way to do so.

If window.ethereum gets set by the Coinbase Wallet extension, there is suppose to be a window.ethereum.providers object. You can then go through each one, find MetaMask or Coinbase, and set the preferred one as the provider:

MetaMask conflicting with Coinbase wallet

However, it seems that MetaMask is has priority over this, and sets window.ethereum WITHOUT the .providers object.

I've attempted to load / find the Coinbase Wallet provider during and after Page Load, but it doesn't seem to exist. Again, I'm assuming MetaMask gets set as the provider before Coinbase injection even exists.

Is there a way to let the user set the provider / wallet that is being used using basic web3 JS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不离久伴 2025-01-30 08:43:58

在Chrome上安装了Coinbase和MetAmask扩展程序的此功能进行了一些测试。它将打开一个窗口供您选择要连接的钱包,然后使用该钱包中的第一个地址设置帐户。

async function getWallet() {
  try{
    const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
    let account = accounts[0];
    return account
  } catch (error) {
    console.log(error);
  }
}

Have had some testing with this function with coinbase and metamask extensions both installed on chrome. It will open a window for you to choose which wallet you want to connect and then use the first address in that wallet to set the account.

async function getWallet() {
  try{
    const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
    let account = accounts[0];
    return account
  } catch (error) {
    console.log(error);
  }
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文