Skip to content

[Bug]: calling wallet_addEthereumChain throws error -32603 #32165

Open
@doubleppereira

Description

@doubleppereira

Describe the bug

When trying to add a network from any dapp MM throws an unexpected error even though it added network.

Here is a codesandbox of the issue on add network: https://codesandbox.io/p/sandbox/connect-metamask-plkgo
this example adds gnosis network and MM throws an error -32603, message
:
"f is not a function"
stack
:
"TypeError: f is not a function\n at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-0.js:1:105287\n "

Expected behavior

When adding a network from a dapp like:

 "method": "wallet_addEthereumChain",
 "params": [
  {
    chainId: "0x64",
    chainName: "Gnosis",
    rpcUrls: [
      "https://rpc.gnosischain.com"
    ],
    iconUrls: [
      "https://xdaichain.com/fake/example/url/xdai.svg",
      "https://xdaichain.com/fake/example/url/xdai.png"
    ],
    nativeCurrency: {
      name: "XDAI",
      symbol: "XDAI",
      decimals: 18
    },
    blockExplorerUrls: [
      "https://blockscout.com/poa/xdai/"
    ]
  }
],
});

like as provided by the documentation on https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_addethereumchain/ with valid configuration it shouldnt throw any error.

Screenshots/Recordings

Image

Steps to reproduce

  1. go to codesanbox: https://codesandbox.io/p/sandbox/connect-metamask-plkgo
  2. click on add network
  3. check the alert that outputs the exception returned by MM

Error messages or log output

useErrorHandler.tsx:107 Extension error: code: -32603 
{code: -32603, message: 'f is not a function', data: {…}}
code
: 
-32603
data
: 
cause
: 
message
: 
"f is not a function"
stack
: 
"TypeError: f is not a function\n  at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-0.js:1:105287\n  at async chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background-0.js:1:98525"
[[Prototype]]
: 
Object
[[Prototype]]
: 
Object
message
: 
"f is not a function"
[[Prototype]]
: 
Object

Detection stage

In production (default)

Version

12.16.0

Build type

None

Browser

Chrome

Operating system

MacOS

Hardware wallet

No response

Additional context

No response

Severity

  • Medium

We require the handling of error in case the user rejects or we wrongly add a wrong configuration to add network

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    To be fixed

    Status

    To be triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions