首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Metamask不切换链到Rinkeby测试网

Metamask不切换链到Rinkeby测试网
EN

Ethereum用户
提问于 2022-05-04 05:11:03
回答 1查看 754关注 0票数 2

我试图调用这个函数,它将触发元请求将链更改为rinkeby测试网,但它不起作用,它适用于其他链,比如多边形维护网和二进制维护网,但是对于Rinkeby,它什么也不做。

代码语言:javascript
复制
await window.ethereum.request({
    method: 'wallet_switchEthereumChain',
    params: [{
       chainId: `0x${Number(4).toString(16)}`,
       chainName: "Rinkeby",
       nativeCurrency: {
          name: "Rinkeby Ether",
          symbol: "RIN",
          decimals: 18
       },
       rpcUrls: ["https://rinkeby.infura.io/v3/"],
       blockExplorerUrls: ["https://rinkeby.etherscan.io"]
    }]
});
EN

回答 1

Ethereum用户

回答已采纳

发布于 2022-05-04 07:30:07

我认为你混淆了“切换”和“添加”网络的功能。交换网络的功能只需通过chainId即可。

这就是我的代码的样子:

代码语言:javascript
复制
let web3 = window.ethereum;

await web3
  .request({
    method: "wallet_switchEthereumChain",
    params: [{ chainId: chainId }],
  })
  .catch(() => {});
票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/127499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档