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

walletconect v2 chains not supported

Open andriirak opened this issue 3 years ago • 26 comments

Describe the bug I have Error: Unsupported chains. after init @walletconnect/ethereum-provider with chains length > 1 await EthereumProvider.init({ projectId: walletConnectProjectId, walletConnectVersion: 2, chains: [Web3Chains.Ethereum, Web3Chains.Goerli]})

To Reproduce Steps to reproduce the behavior

  1. call init action from @walletconnect/ethereum-provider with chains: [Web3Chains.Ethereum, Web3Chains.Goerli]
  2. connect metamask mobile wallet with walletconnect v2
  3. See error in console Error: Unsupported chains

Expected behavior Metamask mobile wallet should be connected without any error

Smartphone (please complete the following information):

  • Device: Redmi note 8
  • OS: Android
  • 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 23 '23 08:06 andriirak

Having the same problem with chains: [137] for Poly

Raggaer avatar Jun 24 '23 16:06 Raggaer

Having the same problem with chains: [7001] for ZetaChain Testnet

kecson avatar Jun 25 '23 03:06 kecson

I was facing the same problem and bypassed it by setting my chains as optional.

EthereumProvider.init({
 // other config properties 
 chains: [1], //need to have at least one, so I set mainnet chainId
 optionalChains: [5, 7001] // add here all your chains 
})

ccosmincc avatar Jun 26 '23 15:06 ccosmincc

If you add the chainids to the optionalChains you are able to connect, but afterwards you are not able to switch to the defined optional chains.
Also the error happens when you provide more than one chain in the chains prop.

EthereumProvider.init({
 // other config properties 
 chains: [1, 5], //need to have at least one, so I set mainnet chainId
 optionalChains: [7001] // add here all your chains 
})

And it won't work.

compojoom avatar Jun 27 '23 09:06 compojoom

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

anaamolnar avatar Jun 27 '23 16:06 anaamolnar

Facing the same issue. Fixed it by passing optionalChains. Check out this discussion: https://github.com/orgs/WalletConnect/discussions/2920

mostafa-rio avatar Jul 03 '23 05:07 mostafa-rio

@anaamolnar hi, any news, when will it be ready?

andriirak avatar Jul 04 '23 14:07 andriirak

Facing the same issue. Fixed it by passing optionalChains. Check out this discussion: https://github.com/orgs/WalletConnect/discussions/2920

Fixing it with optionalChains doesn't really fix it. Problem using that approach is that after you connect and then want to switch chains it won't work. Either you'll get an error saying "Error: Failed to switch to chain 'eip155:1'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method" or you'll just get a positive resolution (null) but the chain in the Metamask won't change at all.

@anaamolnar is there any progress on this issue? Using multiple chains just won't let us connect our mobile MM apps with our dapps. Using optionalChains rises other issues.. So we're very much interested into solving this one.

Happens with Metamask Android and iOS apps ver 7.3.0 using latest "@web3-react/walletconnect-v2": "8.3.7"

ps: using Metamask browser extension, all works well.

nexus6nexus6 avatar Jul 24 '23 12:07 nexus6nexus6

Any updates on this issue? It's blocking dApps that support multiple chains from fully integrating with Metamask Mobile via Wallet Connect.

meeh0w avatar Aug 07 '23 13:08 meeh0w

Any updates? This has being a major pain since the wallet-connect migration to v2.

paro-paro avatar Aug 08 '23 11:08 paro-paro

Having the same problem for 719 (Shiba Inu Testnet)

echovl avatar Aug 24 '23 01:08 echovl

Please update MetaMask to version 7.4.x should be fixed

glitch-txs avatar Aug 24 '23 02:08 glitch-txs

Hi @glitch-txs

I am on

Metamask Mobile: v7.5.0 (1167) and

"@walletconnect/ethereum-provider": "^2.10.0",
"@walletconnect/modal": "^2.6.1",
<script setup lang="ts">
import { EthereumProvider } from '@walletconnect/ethereum-provider'

const handleConnect = async () => {
  try {
    const provider = await EthereumProvider.init({
      projectId: 'foo',
      chains: [1, 42220],
      showQrModal: true,
    })

    await provider.enable()

    console.log(provider.accounts)
  } catch (error) {
    console.log(error)
  }
}
</script>

<template>
  <div>
    <h1>Walletconnect + Metamask</h1>
    <button type="button" @click="handleConnect">Conectar</button>
  </div>
</template>

And the "Error: Unsupported chains." still there.

https://github.com/MetaMask/metamask-mobile/assets/43136874/074a5049-5418-4aca-a995-7f6840a80e44

paro-paro avatar Aug 25 '23 11:08 paro-paro

@paro-paro MetaMask only supports one required chain, you need to move the rest to optionalChains

glitch-txs avatar Aug 25 '23 15:08 glitch-txs

@glitch-txs thanks!

I understand that the 7.4.x fix was related to the "Error: Failed to switch to chain 'eip155:1'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method"

I check it out and it seems to be working fine so sorry for my confusion.


Still, I have found another issue related to the walletconnect + metamask-mobile integration.

Steps to reproduce:

  1. Init your ethereum provider with two networks (ETH and CELO)
const provider = await EthereumProvider.init({
  projectId: 'foo',
  chains: [1],
  optionalChains: [42220], // celo
  showQrModal: true,
})
  1. Connect you metamask mobile wallet by scanning the QR code (make sure metamask is connected to Ethereum Mainnet).

  2. Switch to CELO network from the dapp with the wallet_switchEthereumChain method.

await provider.request({
   method: 'wallet_switchEthereumChain',
      params: [
        {
          chainId: '0xa4ec',
        },
      ],
    })
  1. Trigger a personal_sign request.

So far, so good.

Metamask will connect successfully to the dapp (2), the wallet_switchEthereumChain will prompt the user to change the network to CELO (3) and the personal_sign prompt will also be displayed in the metamask wallet (4).

But, once in this state, if the user...

  1. Switches back to ETH network.

In this case, metamask will not prompt the user to change the network but the provider will effectively reflect this change on the chainChanged event. I believe this is expected behaviour (changing again to CELO will behave the same way, not prompting the user but reflecting the change in the provider).

  1. Triggers again the personal_sign request.

Here is when I find the problem:

Metamask will properly detect that the provider is connected to ETH and before displaying the personal_sign prompt, will ask the user to change the network first (since metamask is still connected to CELO).

But after that, it wont sequentially display the sign prompt. The user will have to trigger again the personal_sign request (by, for example, clicking the sign message button twice which is unintuitive and feels like the dapp is not working).

Fortunately, this is the expected behaviour we get if the user switches again to the CELO network and launches the sign request:

=> Metamask will prompt the user for a network change (really nice) and right after that will prompt the sign request (so perfect).

You can find a reproduction repo here in case is useful.

Thanks in advanced.

paro-paro avatar Sep 05 '23 11:09 paro-paro

Maybe I should open a different issue for this @glitch-txs ?

paro-paro avatar Sep 05 '23 11:09 paro-paro

@paro-paro could you post this on a new MetaMask issue? I was actually about to QA this exact flow. Thanks! 🤝

glitch-txs avatar Sep 05 '23 13:09 glitch-txs

Great @glitch-txs ! 😄

Here it is https://github.com/MetaMask/metamask-mobile/issues/7138

Thanks a lot!!

paro-paro avatar Sep 05 '23 14:09 paro-paro

This issue has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 7 days. Thank you for your contributions.

github-actions[bot] avatar Dec 04 '23 14:12 github-actions[bot]

any updates?

andriirak avatar Dec 04 '23 14:12 andriirak