MetaMask/metamask-sdk

[Bug]: undefined chainId and can't switch

AlansaladA opened this issue · 6 comments

SDK

Web

Provide environment information

webapp in telegram

MetaMask SDK Version

0.20.2

MetaMask Mobile app Version

7.22.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

Steps to Reproduce:

  1. Click the "Connect" button in MetaMask.
  2. Successfully retrieve the chainId.
  3. Refresh the page.
  4. Auto comfirm.

Observed Behavior:

  • On the first connection, the chainId is successfully retrieved.
  • After refreshing the page and reconnecting, MetaMask automatically confirms the connection.
  • In this scenario, the chainId is undefined.
  • When attempting to use wallet_switchEthereumChain to switch to the current chain, there is no response. The method neither proceeds to the next step nor throws any errors.

Expected Behavior

retrieve the chainId.

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

No response

To Reproduce

image
image

Hi @AlansaladA ! When changing to the chain that MetaMask already has selected the response purposely returns Null, this is the expected behaviour.
Can you please give it a go with MetaMask version 7.23.0 as we made significant changes to the protocol that will make the behaviour a lot more fluent.

Hi @christopherferreira9. It seems I might not have articulated my problem clearly. The issue occurs when refreshing the page within a short period; upon reconnecting, the retrieved chainId is undefined. My application is a web app within Telegram.

But now, after updating to MetaMask version 7.23.0 and wagmi with metaskmask-sdk version 0.20.5, my page cannot connect at all. I am seeing many errors in the console saying, “Error: decryptMessage: Keys not exchanged - missing otherPubKey”. These errors occur in many instances, even before I click to connect the wallet.

Could you provide any resources or information about connecting with the new version of MetaMask?

image
On Android phones

Hi! I'm sorry, I completely misunderstood the issue you're having. Are you able to share a dapp or a repo where we can try to reproduce ourselves?
In the meantime, can you try to terminate the sdk before connecting? This will always create a new connection which is not ideal but at least we get to know if the initial connection actually works in order to allow us to debug further. You can do so via sdk?.terminate() right before sdk?.connect().

Sorry, I'm on holiday these days. I just tested the new version and found that I can automatically and persistently get wallet data. I think my problem has been solved. Thanks

Hi @AlansaladA ! I'm glad the issue is solved! Please feel free to open a new issue or create a new question if you encounter another issue.