Skip to content

A simple module to determine if your provider is on the mainnet or testnet.

License

Notifications You must be signed in to change notification settings

HowardWei/web3-network-detective

 
 

Repository files navigation

web3-network-detective

NPM version Build status Coverage Status NPM Downloads

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

index.js:34-78

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

  1. Make sure you have an account.json file outside this repo, that contains one JSON object with two properties address and privateKey, like so: {"address": "0x000...", "privateKey": "000..."}.
  2. Run npm run deploy
npm run deploy

Tests

npm test

LICENCE

MIT -- LICENCE

About

A simple module to determine if your provider is on the mainnet or testnet.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%