web3-react
web3-react copied to clipboard
Cant Switch Networks: Failed to execute 'postMessage' on 'Window': Symbol(react.element) could not be cloned.
Hi Coders,
I'm currently dealing with this problem : 'RPC Error: Failed to execute 'postMessage' on 'Window': Symbol(react.element) could not be cloned' every time I'm clicking on a button when I'm trying to switch networks.
I have coinbase and injected installed . I hope both its not causing this error.
code 1 : -- for changing networks const changeNetwork = async ({ networkName, setError }) => {
try {
if (!window.ethereum) throw new Error("No crypto wallet found");
await window.ethereum.request({
method: "wallet_switchEthereumChain",
params: [{ ...networks[networkName]}]
});
} catch (err) {
setError(err.message);
try {
// let provider = window.ethereum;
await window.ethereum?.request({
method: 'wallet_addEthereumChain',
params: [ {chainId: `0x${Number(1).toString(16)}`}]
});
} catch (err){
setError(err.message);
}
}
};
code2 : -- menu/buttons to switch networks const menu = (
<Menu onClick={handleNetworkSwitch} >
<Menu.Item key='1' icon={<PolygonLogo/>} onClick={() => handleNetworkSwitch("polygon")} style={styles.item} >
<span style={{ marginLeft: "5px" }}>{networks.polygon.chainName}</span>
</Menu.Item>
<Menu.Item key='2' icon={<BSCLogo/>} onClick={()=> handleNetworkSwitch("bsc")} style={styles.item} >
<span style={{ marginLeft: "5px" }}>{networks.bsc.chainName}</span>
</Menu.Item>
<Menu.Item key='3' icon={<ETHLogo/>} onClick= {() => handleNetworkSwitch("ethereum")} style={styles.item}>
<span style={{ marginLeft: "5px" }}>{networks.ethereum.chainName}</span>
</Menu.Item>
);
Thanks for your help Dee