Web3js MetaMask – How to Check the Current MetaMask Network?

metamasknetworkidweb3js

How to check the current MetaMask network?

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

Best Answer

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