Add network with existing chain ID via API

It is method from MetaMask docs. I didn’t yet actually tried it in code but docs say that request will be rejected because of chain id:

https://docs.metamask.io/guide/rpc-api.html#wallet-addethereumchain

interface AddEthereumChainParameter {
  chainId: string; // A 0x-prefixed hexadecimal string
  chainName: string;
  nativeCurrency: {
    name: string;
    symbol: string; // 2-6 characters long
    decimals: 18;
  };
  rpcUrls: string[];
  blockExplorerUrls?: string[];
  iconUrls?: string[]; // Currently ignored.
}

MetaMask will automatically reject the request under the following circumstances:

  • If the RPC endpoint doesn’t respond to RPC calls. NOTE: Calls are made from the extension’s background page, not the foreground page. If you use an origin allowlist, they will be blocked.
  • If the RPC endpoint returns a different chain ID when eth_chainId is called.
  • If the chain ID corresponds to any default MetaMask chains.
2 Likes