【问题标题】:How to Make a Custom Chain Connect Button With Ethers.js如何使用 Ethers.js 制作自定义链连接按钮
【发布时间】:2021-11-07 20:05:36
【问题描述】:

我想像 arbiscan.io 底部那样连接到自定义网络

我将如何使用 ethers.js 框架来做到这一点?

单击该按钮应将仲裁网络添加到用户的 Metamask。

【问题讨论】:

    标签: javascript ethereum web3 ethers.js


    【解决方案1】:

    你应该使用以太坊库:

    async function changeNetwork(){
    await ethereum.request({ method: 'wallet_addEthereumChain',
       params:[
          {chainId: "IN_HEXADECIMAL_FORM",
          chainName: "CHAIN_NAME",
          nativeCurrency: {
             name: "NATIVE_CURRENCY_NAME",
             symbol: "NATIVE_CURRENCY_SYMBOL",
             decimals: NATIVE_CURRENCY_DECIMALS //In number form
          },
          rpcUrls: ["BLOCKcHAIN_RPC_URL"],
          blockExplorerUrls?: ["BLOCKCHAIN_EXPLORER"]
       ]});
    }
    

    更多信息见this document

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 2012-10-13
      • 1970-01-01
      • 2021-11-01
      • 2010-11-23
      相关资源
      最近更新 更多