wallet_switchEthereumChain not works with walletconnect v2
Describe the bug calling wallet_switchEthereumChain didn`t change wallet selected chain
To Reproduce Steps to reproduce the behavior
- use walletconnect v2 provider, metamask mobile app version v7.0.1(1126)
- connect metamask wallet and call wallet_switchEthereumChain action
await provider.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: Web3Util.toHex(chainId) }], }); - Select metamask wallet
- In the wallet there are no any request and wallet chain not changed
Expected behavior Should works as as chrome app, request to change wallet chain
Smartphone (please complete the following information):
- Device: Redmi note 8
- OS: android 10
- App Version v7.0.1(1126)
to be added after bug submission by internal support / PM Severity
- How critical is the impact of this bug on a user?
- Add stats if available on % of customers impacted
- Is this visible to all users?
- Is this tech debt?
@andriirak Thanks for reporting! I will pass this on to the team.
I can also confirm after switch chain call, sign call also does not work (sign works if it is called directly without switch chain), so it looks like switch chain feature was not even tested with WalletConnect V2 before the release. Also if chain is switched manually from app then dapp/walletconnect v2 does not receive any chain changed event.
Running into the same issue with latest Android and iOS MM app. While connected via WC2 flow, can't get MM app to display a personal_sign request if the wallet's currently selected chain does not match the dapp's chain - and the dapp can't get the wallet to switch it either.
This could really use a quick fix 🙏
Hello, it looks like wallet_switchEthereumChain is working with latest @walletconnect version. so it seem it was walletconnect issue.
Commenting from WalletConnect, this has been resolved. Please make sure you're using ethereum-provider 2.8.4.
@finessevanes Still experiencing this issue after upgrading to ethereum-provider 2.8.4
https://github.com/wagmi-dev/references/issues/393
Running into the same issue with latest Android and iOS MM app. While connected via WC2 flow, can't get MM app to display a
personal_signrequest if the wallet's currently selected chain does not match the dapp's chain - and the dapp can't get the wallet to switch it either. This could really use a quick fix 🙏
same problem
Commenting from WalletConnect, this has been resolved. Please make sure you're using ethereum-provider 2.8.4.
"@walletconnect/ethereum-provider": "^2.8.6",
"@walletconnect/modal": "^2.5.9",
still not working correctly
It still has bugs with wc v2 auto switch chain integration (among required/approved chains), but if you send wallet_switchEthereumChain or via viem's switchChain directly it works.
@finessevanes @imaksp
for the first request wallet_switchEthereumChain it works, MM received popup confirmation but all next requests failed
for example if user changed blockchain manually to Goerli in the MM wallet, all next requests wallet_switchEthereumChain to Ethereum will change chaindId inside walletconnect provider, but mobile MM wallet still have Goerli chain
Yes its very confusing, I also noticed that sometimes chain switch was successful inside walletconnect without user apporval like in multichain wallet & metamask keeps showing the previously selected network.
The problem also occurs with walletconnect v2.9.0.
Other library information is listed below.
wagmi 1.3.8 viem 1.2.10
The code is like the picture below, and if you manually change the chain ID in the Metamask app, no error occurs.
I encountered the same problem, waiting for repair
I encountered the same problem, waiting for repair
This is and isn't the same issue. The error you are getting is caused by the fact that WCv2 requires that you explicitly include the methods that your provider is going to call whne you initialize the provider, and you haven't included wallet_switchEthereumChain in your array of permitted methods.
While adding it to the list prevents the specific error you posted. Unfortunately, it still wont allow you to switch chains.
still having this issue any fix?
When calling the switchNetwork() in wagmi, the walletClient, signer and network on my dapp switched to the correct network but not my metamask mobile (no-popup and stay at the previous network page), then when try to proceed with a contract interaction theres no pop-up as well, but everything works fine after switching to the correct network manually in metamask mobile
Still having the same issue. I'm developing a react-native DApp and when executing:
await provider.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: ethers.utils.hexValue(DEFAULT_CHAIN_ID) }],
});
I don't get any response from metamask. I'm using the following dependency:
"@walletconnect/modal-react-native": "^1.0.0-rc.6"
And metamask mobile version is: 7.3.0.
Also, when I try to send a transaction using a signer obtained through the web3Provider instance, metamask opens but it only shows the pop-up with all the transaction information if the provider chainId matches the current selected chain in metamask. Related to this issue, the "getNetwork()" method of my web3Provider instance is not returning the chainId corresponding to the selected network in metamask (it's returning the value of the only chain that is present on my eip155 namespace). The same happens if I directly execute:
await provider.request({
method: "eth_chainId",
params: []
})
As you see, the only way to make my dapp work properly using WC2 is selecting the chain manually in the metamask app.
I have also encountered the same problem.
This issue has been occurring for a long time, and I hope it can be resolved as soon as possible. It greatly affects the user's interactive experience.
Two issues:
- When calling the
wallet_switchEthereumChainmethod, after the first time, the Metamask app will not pop up the window to switch chains again. - When switching chains in the Metamask app, the page will not receive a
chainChanged Event.
Same here.
We have 3 chains that we support on dapp. We managed to connect to MM mobile using chains and optionalChains in the connector initialization step.
But when trying to switch chain after we connect our dapp with metamask mobile using wallet_switchEthereumChain method gives us and error:
Error: Failed to switch to chain 'eip155:1'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.
wallet_switchEthereumChain method works nicely with MM chrome plugin (10.33.1), but not with MM app on Android (7.3.0), nor iOS (7.3.0).
We are using the latest "@web3-react/walletconnect-v2": "8.3.7"
ps: We were trying to fallback to wallet_addEthereumChain method whenever wallet_switchEthereumChain fails, but then we're getting code: -32601, message: 'the method wallet_addEthereumChain does not exist/is not available' error.
To me this all looks like comming from a basic problem, Metamask not supporting multiple chains in the new WalletConnect options - see here: https://github.com/MetaMask/metamask-mobile/issues/6688#issuecomment-1647846096
how is this not fixed yet? its not possible for dapps to switch chains in metamask, this has effective broke defi on mobile...
any updates? I can't test and use my mobile web app with this issue
