我试图调用这个函数,它将触发元请求将链更改为rinkeby测试网,但它不起作用,它适用于其他链,比如多边形维护网和二进制维护网,但是对于Rinkeby,它什么也不做。
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"]
}]
});发布于 2022-05-04 07:30:07
我认为你混淆了“切换”和“添加”网络的功能。交换网络的功能只需通过chainId即可。
这就是我的代码的样子:
let web3 = window.ethereum;
await web3
.request({
method: "wallet_switchEthereumChain",
params: [{ chainId: chainId }],
})
.catch(() => {});https://ethereum.stackexchange.com/questions/127499
复制相似问题