net_peerCount
https://api.triport.io/v1/ethReturns the number of peers currently connected to the Ethereum node, encoded as a hexadecimal integer.
net_peerCount reports how many peers the node serving your request is
currently connected to on the Ethereum peer-to-peer network. The count is
returned as a hex-encoded integer string (e.g. "0x2a" for 42 peers).
Use it as a lightweight liveness/health signal — a healthy node maintains a
stable, non-zero peer count. It pairs naturally with
net_listening (is the node accepting connections) and
net_version (which network the node is on).
The value reflects the state of the node that handled the request at that moment; because requests may be served by different backends, treat the number as an instantaneous reading rather than a fixed property of your endpoint.
Parameters
This method takes no parameters. Send an empty params array.
——optionalparams must be [].Response
Response fields
| Field | Type | Description |
|---|---|---|
result | string | Number of connected peers as a hex-encoded integer (e.g. "0x2a" = 42). |
Errors
| Code | Meaning | When it happens |
|---|---|---|
-32001 | trial_expired | The API key's trial period has ended; upgrade to a paid tier to continue. |
-32003 | rate_limited | You exceeded the requests-per-second limit for your tier (free 10 · basic 20 · pro 100 · business 250 RPS). Retry after backing off. |
Errors follow the standard JSON-RPC error envelope. See Errors for the full structure and shared error codes.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/eth", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "net_peerCount",
params: [],
}),
});
const { result } = await res.json();
const peers = parseInt(result, 16);
console.log(`Connected peers: ${peers}`);TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
const peerCountHex = await client.eth.rpc<string>("net_peerCount", []);
console.log(`Connected peers: ${parseInt(peerCountHex, 16)}`);Python (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
peer_count_hex = client.eth.rpc("net_peerCount", [])
print(f"Connected peers: {int(peer_count_hex, 16)}")Notes
- The result is hex-encoded — convert with
parseInt(value, 16)(JS/TS) orint(value, 16)(Python) before using it numerically. - A result of
"0x0"means the node currently has no connected peers, which usually indicates it is still discovering peers or is unhealthy. - Available on the free tier; no scope required.
- Related:
net_listening,net_version,eth_syncing.