4

How to check the current MetaMask network?

For example, if the current network is Rinkeby, I need the string "rinkeby".

2 Answers 2

9

You can check the current network chain ID like this:

console.log(window.ethereum.networkVersion, 'window.ethereum.networkVersion');

And these are the chain IDs for the most used ethereum networks:

  1. Mainnet: 1
  2. Kovan: 42
  3. Ropsten: 3
  4. Rinkeby: 4
  5. Goerli: 5
6
  • 1
    typeof window.ethereum.networkVersion is string. Sep 29, 2021 at 16:07
  • 1
    I never said it's not a string, it's the network ID represented as string. Sep 29, 2021 at 20:17
  • 😄 😄 yeah, I just added it to avoid confusion. Sep 30, 2021 at 10:38
  • 1
    Is there a place I can find all chain ids ? Lets say if I want to know the chain id of matic main chain, where should I check. Sorry if this is a dumb question. Newbie here ! Nov 19, 2021 at 13:05
  • @TheEhsanSarshar very important note, thank you! Because when you listen to the chainChanged event it returns a number.
    – ihorbond
    Dec 24, 2021 at 5:48
2

@vishnusatis check this website to find all chain ids. https://chainlist.org/

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.