Skip to content

Instantly share code, notes, and snippets.

@devonwesley
Last active December 20, 2017 02:24
Show Gist options
  • Save devonwesley/966d8b977a831a33816a436e6327aa95 to your computer and use it in GitHub Desktop.
Save devonwesley/966d8b977a831a33816a436e6327aa95 to your computer and use it in GitHub Desktop.
A code snippet that checks which ethereum network your on.
function currentNetwork() {
const network = web3.eth.getBlock(0).hash
const main = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
const test = '0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d'
switch (network) {
case main:
return 'Main Net'
case test:
return 'Ropsten Network'
default:
return 'TestRPC Testnet'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment