引发错误的代码片段:
const { ethereum }: any = window;
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId }],
});
尝试使用 ethers.js v6:
const ETHERSJS_PROVIDER = new BrowserProvider(ethereum);
await ETHERSJS_PROVIDER.send('wallet_switchEthereumChain', [
{ chainId },
]);
当我安装了 Coinbase 扩展时,我发现了同样的错误。 Coinbase 扩展似乎有错误。