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.


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
| improve this answer | |
  • 1
    Checking the hash of the latest block would be an additional method of checking 1. – Matthew Schmidt Aug 25 '17 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.')
| improve this answer | |
  • 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 '17 at 16:49

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.