metamask-mobile icon indicating copy to clipboard operation
metamask-mobile copied to clipboard

wallet_switchEthereumChain not works with walletconnect v2

Open andriirak opened this issue 3 years ago • 56 comments

Describe the bug calling wallet_switchEthereumChain didn`t change wallet selected chain

To Reproduce Steps to reproduce the behavior

  1. use walletconnect v2 provider, metamask mobile app version v7.0.1(1126)
  2. connect metamask wallet and call wallet_switchEthereumChain action await provider.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: Web3Util.toHex(chainId) }], });
  3. Select metamask wallet
  4. 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 avatar Jun 21 '23 11:06 andriirak

@andriirak Thanks for reporting! I will pass this on to the team.

anaamolnar avatar Jun 21 '23 21:06 anaamolnar

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.

imaksp avatar Jun 22 '23 07:06 imaksp

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 🙏

vkuts avatar Jun 26 '23 18:06 vkuts

Hello, it looks like wallet_switchEthereumChain is working with latest @walletconnect version. so it seem it was walletconnect issue.

imaksp avatar Jun 27 '23 11:06 imaksp

Commenting from WalletConnect, this has been resolved. Please make sure you're using ethereum-provider 2.8.4.

finessevanes avatar Jun 27 '23 13:06 finessevanes

@finessevanes Still experiencing this issue after upgrading to ethereum-provider 2.8.4

https://github.com/wagmi-dev/references/issues/393

zdenham avatar Jun 28 '23 23:06 zdenham

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 🙏

same problem

hamberluo avatar Jul 04 '23 07:07 hamberluo

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

andriirak avatar Jul 04 '23 08:07 andriirak

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.

imaksp avatar Jul 04 '23 12:07 imaksp

@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

andriirak avatar Jul 04 '23 14:07 andriirak

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.

imaksp avatar Jul 04 '23 14:07 imaksp

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.

image

siosio34 avatar Jul 07 '23 08:07 siosio34

I encountered the same problem, waiting for repair

eb8d52c9e6a15cf055c286ad7ec37444

zhy023 avatar Jul 11 '23 04:07 zhy023

I encountered the same problem, waiting for repair

eb8d52c9e6a15cf055c286ad7ec37444

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.

equalogix avatar Jul 11 '23 18:07 equalogix

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

jingxuan98 avatar Jul 12 '23 09:07 jingxuan98

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.

urielkelman avatar Jul 23 '23 21:07 urielkelman

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:

  1. When calling the wallet_switchEthereumChain method, after the first time, the Metamask app will not pop up the window to switch chains again.
  2. When switching chains in the Metamask app, the page will not receive a chainChanged Event.

liubin595338764 avatar Jul 24 '23 02:07 liubin595338764

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

nexus6nexus6 avatar Jul 24 '23 09:07 nexus6nexus6

how is this not fixed yet? its not possible for dapps to switch chains in metamask, this has effective broke defi on mobile...

dokocat avatar Jul 31 '23 10:07 dokocat

any updates? I can't test and use my mobile web app with this issue

cosmos-redshift avatar Jul 31 '23 10:07 cosmos-redshift