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

Bug: wallet_switchEthereumChain doesn't switch to a chain added manually through wallet UI #915

Closed
rho-cassiopeiae opened this issue Jul 5, 2023 · 3 comments
Labels
type: bug Something isn't working

Comments

@rho-cassiopeiae
Copy link

Describe the bug

wallet_switchEthereumChain doesn't switch to a chain added manually through wallet UI, but switches successfully when the chain is added programmatically with wallet_addEthereumChain

Steps

    try {
      await provider.request({
        method: "wallet_switchEthereumChain",
        params: [{ chainId: "0x385" }],
      });
    } catch (switchError) {
      // 4902
      if (switchError.code === -32603) {
        try {
          await provider.request({
            method: "wallet_addEthereumChain",
            params: [
              {
                chainId: "0x385",
                chainName: "Optimism Local",
                rpcUrls: ["http://localhost:9545"],
                nativeCurrency: {
                  name: "Ether",
                  symbol: "ETH",
                  decimals: 18,
                },
              },
            ],
          });
        } catch (addError) {
          return addError;
        }
      } else {
          return switchError;
      }
    }

If I first add the Optimism Local chain manually through UI and then try to execute this code, switch chain fails, even though the chain is there.

If I don't add the chain manually, then the first time the code is executed it fails as expected, since the chain is not present, and then offers to add the chain. Once programmatically added, the second time the code executes, the switching succeeds.

Also as you can see from the code, the error code for when trying to switch to an unknown chain is reported as -32603 for some reason, when it should be 4902.

Expected behavior

Switching succeeds.

Version

No response

Additional info

No response

Desktop

  • Chrome
  • Extension version: 3.25.3_0

Smartphone

No response

@rho-cassiopeiae rho-cassiopeiae added the type: bug Something isn't working label Jul 5, 2023
@bangtoven
Copy link
Contributor

sorry for the late response.
it's addressed with this PR #954 and we will release new version soon. thanks.

@SamWilsn
Copy link

Looks like this has popped up again.

@bangtoven bangtoven reopened this Oct 20, 2023
@bangtoven
Copy link
Contributor

please try sdk 4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Development

No branches or pull requests

3 participants