NET methods
The NET API methods provide network-related information.
net_enode
Returns the enode URL.
Parameters
- None
Returns
- Enode URL of the node.
Example
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST http://127.0.0.1:8545/ \
-H "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "net_enode",
"params": [],
"id": 1
}'
{
"jsonrpc": "2.0",
"method": "net_enode",
"params": [],
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": "enode://6a63160d0ccef5e4986d270937c6c8d60a9a4d3b25471cda960900d037c61988ea14da67f69dbfb3497c465d0de1f001bb95598f74b68a39a5156a608c42fa1b@127.0.0.1:30303"
}
net_listening
Whether the client is actively listening for network connections.
Parameters
- None
Returns
- Indicates if the client is actively listening for network connections.
Example
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST http://127.0.0.1:8545/ \
-H "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "net_listening",
"params": [],
"id": 53
}'
{
"jsonrpc": "2.0",
"method": "net_listening",
"params": [],
"id": 53
}
{
"jsonrpc": "2.0",
"id": 53,
"result": true
}
net_peerCount
Returns the number of peers currently connected to the client.
Parameters
- None
Returns
- Number of connected peers in hexadecimal.
Example
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST http://127.0.0.1:8545/ \
-H "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 53
}'
{
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 53
}
{
"jsonrpc": "2.0",
"id": 53,
"result": "0x5"
}
net_services
Returns enabled services (for example, jsonrpc) and the host and port for each service.
note
The --nat-method setting affects the JSON-RPC and P2P host and port values, but not the metrics host and port values.
Parameters
- None
Returns
- Enabled services.
Example
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST http://127.0.0.1:8545/ \
-H "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "net_services",
"params": [],
"id": 1
}'
{
"jsonrpc": "2.0",
"method": "net_services",
"params": [],
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"jsonrpc": {
"host": "127.0.0.1",
"port": "8545"
},
"p2p": {
"host": "127.0.0.1",
"port": "30303"
},
"metrics": {
"host": "127.0.0.1",
"port": "9545"
}
}
}
net_version
Returns the network ID.
Parameters
- None
Returns
- Current network ID.
Example
- curl HTTP request
- wscat WS request
- JSON result for Mainnet
curl -X POST http://127.0.0.1:8545/ \
-H "Content-Type: application/json" \
--data '{
"jsonrpc": "2.0",
"method": "net_version",
"params": [],
"id": 53
}'
{
"jsonrpc": "2.0",
"method": "net_version",
"params": [],
"id": 53
}
{
"jsonrpc": "2.0",
"id": 51,
"result": "1"
}