web3-network-detective

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i web3-network-detective

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • silentcicero