Note
This documentation is under construction and the chain3.js 1.0 stable version isn’t released. If you’re using a version v0.1.x of chain3.js then please have a look at chain3js 0.1.x or https://github.com/MOACChain/moac-core/wiki/Chain3.
web3.eth.net¶
Functions to receive details about the current connected network.
getId¶
web3.eth.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.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.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
It’s recommended to use the web3.eth.getChainId method to detect the currently connected chain.
Returns¶
Promise
returnsString
:"main"
for main network"morden"
for the morden test network"rinkeby"
for the rinkeby test network"ropsten"
for the ropsten test network"kovan"
for the kovan test network"private"
for undetectable networks.
Example¶
web3.eth.net.getNetworkType().then(console.log);
> "main"