Skip to content

Instantly share code, notes, and snippets.

@ylv-io
Last active January 14, 2019 12:11
Show Gist options
  • Save ylv-io/7dbaf38d506e2cd4c8e9fabd164a3fd6 to your computer and use it in GitHub Desktop.
Save ylv-io/7dbaf38d506e2cd4c8e9fabd164a3fd6 to your computer and use it in GitHub Desktop.
if (web3js) {
switch (web3js.version.network) {
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 test network.');
break;
case '42':
console.log('This is the Kovan test network.');
break;
default:
console.log('This is an unknown network.');
}
const desiredNetwork = 1;
if (web3js.version.network !== desiredNetwork) {
// ask user to switch to desired network
console.log('Please switch to main network.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment