githubEdit

net_peerCount - Optimism

Example code for the net_peerCount json-rpc method. Сomplete guide on how to use net_peerCount json-rpc in GetBlock.io Web3 documentation.

This method returns the number of peers the node is connected to in the P2P network. A higher peer count generally indicates better network connectivity and reliability. This is useful for monitoring node health.

Parameters

  • None

Request Sample

cURL
curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "net_peerCount",
    "params": [],
    "id": "getblock.io"
}'

Response

A successful response returns the following:

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x12d"
}

Response Parameters

  • id: A unique request identifier, matching the id sent in the request body.

  • jsonrpc: Specifies the use of JSON-RPC version 2.0.

  • result: The number of connected peers as a hexadecimal string. 0x19 equals 25 peers.

Use Case

The net_peerCount method is commonly used for:

  • Network connectivity monitoring

  • Node health assessment

  • P2P network analysis

Web3 Integration

Last updated

Was this helpful?