2

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.

1

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. – Matthew Schmidt Aug 25 '17 at 12:27
1

you can try : version.getnework :

web3.version.getNetwork((err, netId) => {
  switch (netId) {
    case "1":
      console.log('This is mainnet')
      break
    case "2":
      console.log('This is the deprecated Morden test network.')
      break
    case "3":
      console.log('This is the ropsten test network.')
      break
    case "4":
      console.log('This is the Rinkeby network.')
      break;
    case "42":
      console.log('This is the Kovan network.')
    default:
      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 '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.