net_peerCount
Returns number of peers currently connected to the client on Optimism Layer 2.
Parameters
None.
Implementation Examples
- cURL
- JavaScript
curl -X POST https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 1
}'
const response = await fetch('https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'net_peerCount',
params: [],
id: 1
})
});
const data = await response.json();
console.log('Peer count:', parseInt(data.result, 16));
Response Example
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x19"
}
This represents 25 peers connected to the Optimism node.
Need help? Contact our support team or check the Optimism documentation.