A simple module to determine if your web3 provider is on the Ethereum mainnet, (morden) testnet or a custom network.
npm install --save web3-network-detective
import Web3 from 'web3';
import networkDetective from 'web3-network-detective';
// setup example web3 instance
const web3 = new Web3(new Web3.providers.HttpProvider('https://morden.infura.io/'));
// network detective usage
networkDetective(web3.currentProvider, function(detectiveError, detectiveResult){
if (!detectiveError) {
console.log(detectiveResult);
}
});
/*
example detective result:
{
network: 'mainnet', // or 'testnet' or 'custom'
mainnet: true,
testnet: false,
custom: false,
}
*/
Detects the current network of a web3 provider.
Parameters
web3Provider
Object the web3 provider you would like to check the nextwork (i.e. 'livenet' or 'testnet') of.
Returns Object, example:
{
network: 'mainnet', // or 'testnet' or 'custom'
mainnet: true,
testnet: false,
custom: false,
}
- Make sure you have an
account.json
file outside this repo, that contains one JSON object with two propertiesaddress
andprivateKey
, like so:{"address": "0x000...", "privateKey": "000..."}
. - Run
npm run deploy
npm run deploy
npm test
MIT -- LICENCE