【问题标题】:connect to walletconnect with web3modal连接到 walletconnect with web3modal
【发布时间】:2021-10-06 11:00:35
【问题描述】:

当我尝试从信任钱包浏览器连接到我的钱包时,它会将我重定向到谷歌

[1]:https://i.stack.imgur.com/V4PPx.jpg
[2]:https://i.stack.imgur.com/soFxv.jpg

代码是这样的,和trustWallet doc一样

1。如何正确连接到钱包连接?

2。有没有办法通过钱包连接连接到像 ropsten 这样的测试网?

// set chain id and rpc mapping in provider options
        const providerOptions = {
            walletconnect: {
                package: WalletConnectProvider,
                options: {
                    rpc: {
                        56: 'https://bsc-dataseed1.binance.org'
                    },
                    chainId: 56
                }
            }
        }

        const web3Modal = new Web3Modal({
            network: "mainnet", // optional
            cacheProvider: true, // optional
            providerOptions // required
        });

        const provider = await web3Modal.connect();
        await web3Modal.toggleModal();

        // regular web3 provider methods
        const newWeb3 = new Web3(provider);
        const accounts = await newWeb3.eth.getAccounts();

        console.log(accounts);

【问题讨论】:

    标签: web3 wallet-connect


    【解决方案1】:

    如果我理解正确,请尝试

    const provider = await Web3Modal.connectTo('walletconnect')
    

    而不是

    const provider = await web3Modal.connect();
    await web3Modal.toggleModal();
    

    UPD:walletConnect 只是“聚合器”。你不能直接连接到任何钱包(至少是第一次)你应该选择你想要连接的钱包(左边的标签带有按钮将选择你手机上可以连接的应用程序(元掩码,信任,...)右侧选项卡“二维码”将显示您可以在其他设备上使用钱包应用程序(元掩码、信任...)扫描的 qr)。那么如果'cacheProvider'为真,你不需要再次点击它,直到与钱包断开连接

    【讨论】:

      【解决方案2】:

      对于第一个问题,我发现它不起作用,因为我在本地主机上。当我在服务器上启动我的 dapp 时,它很容易在手机上连接到我的信任钱包。 对于第二个问题,我发现了这个:

      walletconnect: {
          package: WalletConnectProvider,
          options: {
            rpc: {
              137: "https://rpc-mainnet.maticvigil.com/",
            },
            network: "matic",
          },
        },
      };
      

      连接到 matic(polygon) 网络,但我无法连接到任何测试网。

      【讨论】:

        猜你喜欢
        • 2022-09-08
        • 2022-07-06
        • 2022-01-08
        • 2021-11-28
        • 2022-06-09
        • 2023-02-18
        • 2022-07-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多