I have a local ganache running and I have a select field in my application where a network can be selected. Once a network is selected I'm running this code to switch to that network in metamask:
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: selectedChainId }],
});
I have added my ganache instance as network to metamask with the following information:
Now when I select my ganache network in my application, metamask always tries to switch to the network "Localhost 8545". I think because it has the same chain id. Thats why I have deleted the "Localhost 8545" network to only have one network with the chain id 1337, but if I try it again metamask still chooses the "Localhost 8545" network, even if it does not exist anymore:
And if I confirm then no network switch is applied and I'm getting no error or something else.
Any idea how I can switch to my ganache network programmatically to test my application with ganache?