Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot switch chain to mainnet when connect with Metamask App (QR) #5803

Closed
teodorus-nathaniel opened this issue Dec 19, 2024 · 2 comments
Closed
Labels

Comments

@teodorus-nathaniel
Copy link

teodorus-nathaniel commented Dec 19, 2024

Versions Used

  • Thirdweb 5.72.0 - 5.79.0
  • Metamask (IOS) v7.37.0 (1512)

How to reproduce:

  • Connect metamask with QR (or wallet connect QR but with metamask mobile app)
  • Put other chain data to chain parameter in WalletConnectModal. If the chain is undefined, then don't put "locked chains" (the locked chains list below) in the first element of chains
  • Switch your metamask wallet connected chain to any chain other than the "locked chains"
  • Call wallet.switchChain(...) to "locked chains".
  • It will cause error May not specify default Metamask chain.
    image

Locked Chains List

  • Eth Mainnet
  • Eth Sepolia
  • Linea
  • Linea Sepolia
    image

Issue Detail

In thirdweb if the chain is not included in approved list, then the flow is:

  1. Call wallet_addEthereumChain
  2. Call wallet_switchEthereumChain

In this case, metamask will throw error if you try to call wallet_addEthereumChain with arg of either one of the locked chains.

Another Related Issue

As thirdweb uses @walletconnect/ethereum-provider under the hood to create the provider, I tested that library and check which chains will be included in approved list.
This library will only include the below ids as approved:

  1. provided chainId from chain props
  2. the current connected chain that user have in their metamask

This makes an issue where if the app is multichain, for example Sepolia and Ozean, and the app wants the user to connect to Ozean first, then we need to put Ozean as the chain props.
Which in turn will make Sepolia not included in approved list, and thirdweb will call wallet_addEthereumChain when switch chain, and throw the error.

Possible Solution

From this comment from metamask's issue
We can apply this kind of behavior in the switchChainWc call

Minimal Reproducible Example

https://github.com/teodorus-nathaniel/thirdweb-bug-reproduce

Copy link

linear bot commented Dec 19, 2024

Copy link
Contributor

This issue has been inactive for 30 days. It is now marked as stale and will be closed in 5 days if no further activity occurs.

@github-actions github-actions bot added the Stale label Dec 27, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
@teodorus-nathaniel and others