web3-network-detective
v1.0.0
Published
A simple module for determining if a web3 provider is on the Ethereum mainnet or testnet.
Downloads
16
Maintainers
Readme
web3-network-detective
A simple module to determine if your web3 provider is on the Ethereum mainnet, (morden) testnet or a custom network.
Install
npm install --save web3-network-detective
Usage
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,
}
*/
API Design
constructor
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,
}
Deployment
- 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
Tests
npm test
LICENCE
MIT -- LICENCE