5

Some web3 enabled websites ask you to switch your network on metamask. How can I do so? Some other websites also allow you to add a network you don't have (for example https://chainlist.org/). I would like to do it too. Example: Metamask asks to switch your network

I am using react and web3 react (https://www.npmjs.com/package/web3-react), which means I am using ethers.js under the hood.

Thank you very much, Thomas

1 Answer 1

9

Here is an example how to make your website to ask the users so they can add and switch to the Matic network:

window.ethereum.request({
    method: "wallet_addEthereumChain",
    params: [{
        chainId: "0x89",
        rpcUrls: ["https://rpc-mainnet.matic.network/"],
        chainName: "Matic Mainnet",
        nativeCurrency: {
            name: "MATIC",
            symbol: "MATIC",
            decimals: 18
        },
        blockExplorerUrls: ["https://polygonscan.com/"]
    }]
});
1
  • Thank you very much Miroslav, it works perfectly!
    – Th0rgal
    Dec 23, 2021 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.