Note

This documentation is work in progress and web3.js 1.0 is not yet released! You can find the current documentation for web3 0.x.x at github.com/ethereum/wiki/wiki/JavaScript-API.

web3.eth.net

Contains functions to receive information about the current network.


getId

web3.eth.net.getId([callback])
web3.bzz.net.getId([callback])
web3.shh.net.getId([callback])

Gets the current network ID.

Parameters

none

Returns

Promise returns Number: The network ID.

Example

web3.eth.net.getId()
.then(console.log);
> 1

isListening

web3.eth.net.isListening([callback])
web3.bzz.net.isListening([callback])
web3.shh.net.isListening([callback])

Checks if the node is listening for peers.

Parameters

none

Returns

Promise returns Boolean

Example

web3.eth.isListening()
.then(console.log);
> true

getPeerCount

web3.eth.net.getPeerCount([callback])
web3.bzz.net.getPeerCount([callback])
web3.shh.net.getPeerCount([callback])

Get the number of peers connected to.

Parameters

none

Returns

Promise returns Number

Example

web3.eth.getPeerCount()
.then(console.log);
> 25

getNetworkType

web3.eth.net.getNetworkType([callback])

Guesses the chain the node is connected by comparing the genesis hashes.

Note

This is not a 100% accurate guess as any private network could use testnet and mainnet genesis blocks and network IDs.

Returns

Promise returns String:
  • "main" for main network
  • "morden" for the morden test network
  • "ropsten" for the morden test network
  • "private" for undetectable networks.

Example

web3.eth.net.getNetworkType()
.then(console.log);
> "main"