【问题标题】:connect to trustwallet and get bsc, eth, btc addresses and balances连接到trustwallet并获取bsc、eth、btc地址和余额
【发布时间】:2021-09-23 09:33:42
【问题描述】:

现在我使用以下代码: https://github.com/Web3Modal/web3modal-vanilla-js-example

但它只连接来自信任钱包的 eth 地址

我尝试将提供程序选项更改为:

const providerOptions = {
      walletconnect: {
        package: WalletConnectProvider,
        options: {
            rpc: {
            56: "https://bsc-dataseed.binance.org/"}
        }
      },

但是没用

在我的信任钱包中,我有 btc 地址、eth 地址、bnb 地址,我想知道所有这些地址和余额。但是现在我只能获取eth地址

我尝试过这样做:

const chainId = 56//await web3.eth.getChainId();
// Get list of accounts of the connected wallet
const accounts = await web3.eth.getAccounts();

但这只给了我 eth 帐户。 那我该怎么办?

【问题讨论】:

    标签: ethereum web3 web3js binance-smart-chain wallet-connect


    【解决方案1】:

    您需要要求用户更改钱包本身的链才能访问不同链上的帐户。目前没有 API 或方法可以强制用户更改链。

    【讨论】:

    • 你可以这样做。例如在thorswap
    • 是的 pancakeswap 也可以这样做
    【解决方案2】:

    就我而言,它适用于 Trust 钱包,但不适用于 metamask 移动应用:

     walletconnect: {
        package: WalletConnectProvider, // required
        options: {
          rpc: {
            56: 'https://bsc-dataseed.binance.org/',
            97: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
          },
          network: "binance", // --> this will be use to determine chain id 56
        },
      },
    

    我不确定是否需要以下代码:

    web3Modal = new Web3Modal({
        network: 'binance', // optional
        cacheProvider: true,
        providerOptions, // required
      })
    

    你可以直接阅读源码了解如何配置: // 选择 BSC 在 Trust 钱包上工作,但不在元掩码上工作 https://github.com/Web3Modal/web3modal/blob/72596699b97d231dfaa5ef04110b61b8dc77d57d/src/providers/connectors/walletconnect.ts#L30 https://github.com/Web3Modal/web3modal/blob/72596699b97d231dfaa5ef04110b61b8dc77d57d/src/helpers/utils.ts#L198

    【讨论】:

      猜你喜欢
      • 2022-09-26
      • 2019-06-28
      • 1970-01-01
      • 2022-11-15
      • 2022-08-19
      • 2022-12-23
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      相关资源
      最近更新 更多