If you're running an application which connects to a node to send and validate transactions, what is the best way to check the node is connected to the real Ethereum main net? I'm thinking of the scenario where the user of the application intentionally feeds the node a fake version of Ethereum so they can modify the state to suit there purposes or fake making the transactions to the real main net chain.

2 Answers 2


There are 2 ways of doing it that I know.

  1. Check the latest block number against whats there in ethstats.net
  2. If you do any txn check for it on etherscan.io
  • 1
    Checking the hash of the latest block would be an additional method of checking 1. Aug 25, 2017 at 12:27

you can try : version.getnework :

web3.version.getNetwork((err, netId) => {
  switch (netId) {
    case "1":
      console.log('This is mainnet')
    case "2":
      console.log('This is the deprecated Morden test network.')
    case "3":
      console.log('This is the ropsten test network.')
    case "4":
      console.log('This is the Rinkeby network.')
    case "42":
      console.log('This is the Kovan network.')
      console.log('This is an unknown network.')
  • This is the programmatic way of doing this. Your answer will be complete if you add how to attach to console, or where to run this code.
    – niksmac
    Aug 25, 2017 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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