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

ChainId as int is wrongly converted to hex / Provided chainId "280" must match the active chainId "640"

Open equalogix opened this issue 3 years ago • 3 comments

Describe the bug Since upgrading to version 7.1.0 (Android) we are getting the following error when attempting to interact with our smart-contracts. Everything works correctly on desktop and iOS. But I get the following error when using the Metamask Browser on Android:

{
    "code":-32603,
    "message":"Provided chainId \"280\" must match the active chainId \"640\"",
    "data": {
        "originalError": {
           "line":3687,
           "column":1879,
           "sourceURL":"index.android.bundle"
       }
   }
}

When using the default browser (Chrome) with WalletConnect V2 I get: {"code": -32603, "message": "Internal error"}

To be clear, what this message is saying is that my "provided chain" is 280 "zkSync-era testnet" and it is not matching the active chain 640. The problem is that 640 is not an actual chain and certainly not a chain that I selected. 640 is the int value of hex 280 ie: parseInt('0x280') === 640. This suggests that somewhere in the code, the chainId was provided as int when it should have been a hex.

Screenshots Not applicable

To Reproduce I don't have an easy way to reproduce this error. It can be reproduced in my dApp, but getting to the point where the contract interaction occurs requires payments. I have a dev version but it is not accessible to the public. I can grant access to MM team if needed.

But the bug should occur generally as follows: You must connect to either zkSync Era testnet (chain 280/0x118) or zkSync Era testnet (chain 324/0x144) and interact with a contract or send a transaction, using ethers.js v5.7. With WCv2 it will open the wallet, but no confirmation pop-up appears, in the dApp you will get an "internal error". If using MM Browser, the error posted above occurs. I suspect that this issue is not specific to zkSync-Era chains, I suspect that it impacts most chains but not Eth-Mainnet, nor Goerli, as these chains will have the same id in both int/hex, eg: Eth mainnet id:1/0x1 => parseInt('0x1') === 1, whereas Polygon id:137/0x89 parseInt("0x137") !== 89 it equals 311

Expected behavior The transaction should proceed and not throw an error.

Smartphone (please complete the following information):

  • Device: Android, various devices have been tested, mostly Samsung (S21) and similar. We also tested iOS devices an those worked as expected.
  • OS: Latest Android
  • App Version: 7.1.0 Note: The error began after the update to 7.1.0

Added notes: Impact on our business: This has broken the functionality of our dApp.

This bug has essentially delayed the launch of the dApp, and will have an over-sized impact since the dApp is seasonal at this point we will loose most of what left the 2023 season.

The following raised issues may be related to this issue: https://github.com/MetaMask/metamask-mobile/issues/6715 => Polygon 137 eth_signTypedData request #6756 chain not specified https://github.com/MetaMask/metamask-mobile/issues/6740 => Polygon 137


to be added after bug submission by internal support / PM Severity

equalogix avatar Jul 11 '23 19:07 equalogix

It appears that the bug is fixed in version 7.2.0.

equalogix avatar Jul 12 '23 02:07 equalogix

Hello, @equalogix. Thanks for the report! Can you please confirm you are no longer experiencing this issue with the new version so I can close this? Thanks.

anaamolnar avatar Jul 18 '23 11:07 anaamolnar

Yes, I can confirm that the issue is resolved. Thank you.

equalogix avatar Jul 18 '23 15:07 equalogix