net_peerCount
curl --request POST \
--url https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 1
}
'import requests
url = "https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm"
payload = {
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 1
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({jsonrpc: '2.0', method: 'net_peerCount', params: [], id: 1})
};
fetch('https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'method' => 'net_peerCount',
'params' => [
],
'id' => 1
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm"
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"method\": \"net_peerCount\",\n \"params\": [],\n \"id\": 1\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"method\": \"net_peerCount\",\n \"params\": [],\n \"id\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"method\": \"net_peerCount\",\n \"params\": [],\n \"id\": 1\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "2.0",
"id": 1,
"result": "0x2a"
}Hyperliquid node API
net_peerCount | Hyperliquid EVM
The net_peerCount JSON-RPC method returns the number of peers currently connected to the client. Chainstack Hyperliquid EVM reference.
POST
/
evm
net_peerCount
curl --request POST \
--url https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 1
}
'import requests
url = "https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm"
payload = {
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 1
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({jsonrpc: '2.0', method: 'net_peerCount', params: [], id: 1})
};
fetch('https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'method' => 'net_peerCount',
'params' => [
],
'id' => 1
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm"
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"method\": \"net_peerCount\",\n \"params\": [],\n \"id\": 1\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"method\": \"net_peerCount\",\n \"params\": [],\n \"id\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"method\": \"net_peerCount\",\n \"params\": [],\n \"id\": 1\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "2.0",
"id": 1,
"result": "0x2a"
}This method is available on Chainstack. Not all Hyperliquid methods are available on Chainstack, as the open-source node implementation does not support them yet — see Hyperliquid methods for the full availability breakdown.
net_peerCount JSON-RPC method returns the number of peers currently connected to the client. This method provides information about the node’s network connectivity and can be used to monitor network health, connectivity status, and the decentralization level of the blockchain network.
Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.
Parameters
This method takes no parameters. Theparams field should be an empty array.
Response
The method returns the number of connected peers as a hexadecimal string.Response structure
Peer count:- Returns the number of connected peers as a hexadecimal string
- Convert from hex to decimal for human-readable count
- Example: “0x2a” equals 42 peers in decimal
Peer connectivity interpretation
Network health indicators:- Higher peer count generally indicates better network connectivity
- Zero peers may indicate network connectivity issues
- Peer count fluctuates based on network conditions and node behavior
- Peer count reflects the distributed nature of the network
- More peers typically mean better data availability and redundancy
- Useful for assessing network resilience and decentralization
Usage example
Basic implementation
// Get peer count
const getPeerCount = async () => {
const response = await fetch('https://hyperliquid-mainnet.core.chainstack.com/YOUR_ENDPOINT/evm', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'net_peerCount',
params: [],
id: 1
})
});
const data = await response.json();
const peerCount = parseInt(data.result, 16);
return {
hex: data.result,
decimal: peerCount
};
};
// Network health monitor
const monitorNetworkHealth = async () => {
const healthStatus = {
peerCount: 0,
status: 'unknown',
timestamp: new Date(),
history: []
};
try {
const { decimal: peerCount } = await getPeerCount();
healthStatus.peerCount = peerCount;
// Determine network status based on peer count
if (peerCount === 0) {
healthStatus.status = 'disconnected';
} else if (peerCount < 5) {
healthStatus.status = 'poor';
} else if (peerCount < 20) {
healthStatus.status = 'fair';
} else if (peerCount < 50) {
healthStatus.status = 'good';
} else {
healthStatus.status = 'excellent';
}
} catch (error) {
healthStatus.status = 'error';
healthStatus.error = error.message;
}
return healthStatus;
};
// Continuous network monitoring
const startNetworkMonitoring = (callback, intervalMs = 30000) => {
const monitor = {
history: [],
isRunning: false,
intervalId: null
};
const checkNetwork = async () => {
const health = await monitorNetworkHealth();
monitor.history.push(health);
// Keep only last 100 readings
if (monitor.history.length > 100) {
monitor.history = monitor.history.slice(-100);
}
callback(health, monitor.history);
};
monitor.start = () => {
if (!monitor.isRunning) {
monitor.isRunning = true;
checkNetwork(); // Initial check
monitor.intervalId = setInterval(checkNetwork, intervalMs);
}
};
monitor.stop = () => {
if (monitor.isRunning) {
monitor.isRunning = false;
clearInterval(monitor.intervalId);
}
};
monitor.getStats = () => {
if (monitor.history.length === 0) return null;
const peerCounts = monitor.history.map(h => h.peerCount);
return {
current: peerCounts[peerCounts.length - 1],
min: Math.min(...peerCounts),
max: Math.max(...peerCounts),
avg: Math.round(peerCounts.reduce((a, b) => a + b, 0) / peerCounts.length),
samples: monitor.history.length
};
};
return monitor;
};
// Network connectivity dashboard
class NetworkDashboard {
constructor() {
this.data = {
current: null,
history: [],
alerts: []
};
}
async updateStatus() {
try {
const health = await monitorNetworkHealth();
this.data.current = health;
this.data.history.push(health);
// Keep history manageable
if (this.data.history.length > 1000) {
this.data.history = this.data.history.slice(-1000);
}
// Check for alerts
this.checkAlerts(health);
} catch (error) {
console.error('Failed to update network status:', error);
}
}
checkAlerts(health) {
const now = Date.now();
// Low peer count alert
if (health.peerCount < 5 && health.status !== 'error') {
this.data.alerts.push({
type: 'low_peers',
message: `Low peer count detected: ${health.peerCount}`,
timestamp: now,
severity: 'warning'
});
}
// Disconnection alert
if (health.peerCount === 0) {
this.data.alerts.push({
type: 'disconnected',
message: 'Node appears to be disconnected (0 peers)',
timestamp: now,
severity: 'critical'
});
}
// Keep only recent alerts (last hour)
this.data.alerts = this.data.alerts.filter(
alert => now - alert.timestamp < 3600000
);
}
getStatus() {
return this.data.current;
}
getHistory(minutes = 60) {
const cutoff = Date.now() - (minutes * 60 * 1000);
return this.data.history.filter(h => h.timestamp.getTime() > cutoff);
}
getAlerts(minutes = 60) {
const cutoff = Date.now() - (minutes * 60 * 1000);
return this.data.alerts.filter(a => a.timestamp > cutoff);
}
generateReport() {
const recent = this.getHistory(60);
if (recent.length === 0) return null;
const peerCounts = recent.map(h => h.peerCount);
const statusCounts = recent.reduce((acc, h) => {
acc[h.status] = (acc[h.status] || 0) + 1;
return acc;
}, {});
return {
timeRange: '60 minutes',
samples: recent.length,
peerStats: {
current: this.data.current?.peerCount || 0,
min: Math.min(...peerCounts),
max: Math.max(...peerCounts),
avg: Math.round(peerCounts.reduce((a, b) => a + b, 0) / peerCounts.length)
},
statusDistribution: statusCounts,
recentAlerts: this.getAlerts(60).length
};
}
}
// Usage examples
getPeerCount().then(result => {
console.log(`Connected peers: ${result.decimal} (${result.hex})`);
});
// Start network monitoring
const monitor = startNetworkMonitoring((health, history) => {
console.log(`Network Status: ${health.status}, Peers: ${health.peerCount}`);
if (health.status === 'poor' || health.status === 'disconnected') {
console.warn('Network connectivity issues detected!');
}
}, 10000); // Check every 10 seconds
monitor.start();
// Stop monitoring after 5 minutes
setTimeout(() => {
monitor.stop();
console.log('Final stats:', monitor.getStats());
}, 5 * 60 * 1000);
// Use network dashboard
const dashboard = new NetworkDashboard();
// Update dashboard every 30 seconds
setInterval(() => {
dashboard.updateStatus().then(() => {
const report = dashboard.generateReport();
if (report) {
console.log('Network Report:', report);
}
});
}, 30000);
Example request
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 1
}' \
https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm
from web3 import Web3
w3 = Web3(Web3.HTTPProvider("YOUR_CHAINSTACK_ENDPOINT"))
peer_count = w3.net.peer_count
print(peer_count)
import { JsonRpcProvider } from "ethers";
const provider = new JsonRpcProvider("YOUR_CHAINSTACK_ENDPOINT");
const peerCount = await provider.send("net_peerCount", []);
console.log(peerCount);
import { createPublicClient, http } from "viem";
const client = createPublicClient({
transport: http("YOUR_CHAINSTACK_ENDPOINT"),
});
const peerCount = await client.request({ method: "net_peerCount" });
console.log(peerCount);
Use your own endpoint in your code. The code examples use a placeholder Chainstack endpoint (YOUR_CHAINSTACK_ENDPOINT) — replace it with your own Hyperliquid node endpoint from the Chainstack console. The curl above uses a shared public endpoint for quick checks only; do not use it in production.
Use cases
Thenet_peerCount method is useful for applications that need to:
- Network monitoring: Monitor blockchain network health and connectivity
- Node diagnostics: Diagnose node connectivity and network issues
- Performance optimization: Optimize application behavior based on network conditions
- Health checks: Implement health checks for blockchain applications
- Alert systems: Create alerts for network connectivity issues
- Load balancing: Make load balancing decisions based on network health
- Monitoring dashboards: Build network monitoring and status dashboards
- DevOps tools: Monitor blockchain infrastructure health
- Research analytics: Analyze network decentralization and topology
- Automatic failover: Implement failover logic based on connectivity
- Network statistics: Generate network connectivity statistics and reports
- Quality assurance: Test network connectivity in different environments
- Troubleshooting: Diagnose network-related issues and connectivity problems
- Infrastructure monitoring: Monitor blockchain node infrastructure health
- SLA monitoring: Monitor service level agreements for network connectivity
Body
application/json
Last modified on June 24, 2026
Was this page helpful?