DEV Community

Karthick S
Karthick S

Posted on

How to add Custom Network in Metamask using Window.Ethereum

What if! if the Metamask has no Network, The user wants to works with.He needs to add manually in Metamask.

It may take sometime. By Copy & Paste! by surfing other website and getting details.

Using ChainLink user can add the Network Easily. But Not all time, it won't works!

The Developer will have a query! Then How to I add Programmatically???

Here Comes up with a Solution!

A JavaScript code using Window.Ethereum.

A Program to Connect Polygon Mainnet Easily

const addNetwork = await window.ethereum.request({
        method: "wallet_addEthereumChain",
        params: [{
          chainId: "0x89",
          rpcUrls: ["https://polygon-rpc.com/"],
          chainName: "Matic Mainnet",
          nativeCurrency: {
            name: "MATIC",
            symbol: "MATIC",
            decimals: 18
          },
          blockExplorerUrls: ["https://polygonscan.com/"]
        }]
      });
Enter fullscreen mode Exit fullscreen mode

Hope it may useful for Dapp Devs.

                    Happy Coding!
Enter fullscreen mode Exit fullscreen mode

Top comments (0)