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
There are 2 ways of doing it that I know.
- Check the latest block number against whats there in ethstats.net
- If you do any
txn
check for it on etherscan.io
-
1Checking 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')
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.– niksmacAug 25, 2017 at 16:49