TriportRPC

net_peerCount

POSThttps://api.triport.io/v1/polygon

Returns the number of peers currently connected to the node's p2p network, as a hexadecimal string.

Polygonpolygon_read_rpcfree 15 rps · basic 20 rps · pro 100 rps · business 250 rps (with burst)

net_peerCount reports how many p2p peers the underlying Polygon node is connected to, encoded as a hex-quantity string (e.g. "0x2a" → 42). It is part of the standard net_* network-info namespace and takes no parameters.

Use it as a lightweight node-health / connectivity signal. The value is most meaningful on the Bor-consensus backends that serve Polygon mainnet (chainId 0x89 / 137), where it reflects the node's real Bor p2p peer count.

Gotcha — value reliability: behind some load-balanced / CDN-fronted infrastructure the peer count is not a real metric. Such backends may return a fabricated constant or "0x0" regardless of the actual peer topology. Treat a zero or suspiciously static value as "unknown" rather than "no peers", and do not build alerting on the absolute number unless you have confirmed your route serves a direct Bor backend. The count is a coarse signal, not a precise gauge.

Parameters

This method takes no parameters. Send an empty params array.

optional
No parameters. params must be [].

Response

Response fields

FieldTypeDescription
jsonrpcstringAlways "2.0".
idnumberEchoes the request id.
resultstringNumber of connected p2p peers as a hex-quantity string (e.g. "0x2a" = 42). Parse with parseInt(result, 16).

Errors

Errors are returned in the standard JSON-RPC error envelope. See the shared errors reference for the full envelope shape and handling guidance.

CodeMeaningWhen it happens
-32601Method not foundThe method name is misspelled or not enabled on the route.
-32001Auth / key errorMissing, invalid, or revoked TRIPORT_API_KEY.
-32002Insufficient tier / scopeKey lacks the polygon_read_rpc capability.
-32003Rate limit exceededPer-tier RPS (incl. burst) was exceeded — back off and retry.
-32004Upstream unavailableNo healthy backend could serve the request.
-32005Upstream timeoutThe backend did not respond in time.

Examples

JavaScript (fetch)

const res = await fetch("https://api.triport.io/v1/polygon", {
  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 { TriportClient } from "@triport/sdk";


const client = new TriportClient({ apiKey: process.env.TRIPORT_API_KEY! });


const result = await client.polygon.rpc<string>("net_peerCount");
const peers = parseInt(result, 16);
console.log(`connected peers: ${peers}`);

Python (triport-sdk)

import os
from triport import TriportClient


client = TriportClient(api_key=os.environ["TRIPORT_API_KEY"])


result = client.polygon.rpc("net_peerCount")
peers = int(result, 16)
print(f"connected peers: {peers}")

Notes

  • No parameters, no caching semantics on the client side — the value changes as peers connect and disconnect, so re-query when you need a fresh reading.
  • This is a net_* info method. Related: net_version (chain id as a decimal string) and net_listening (whether the node is accepting p2p connections — practically always true).
  • For a richer node-identity signal, see web3_clientVersion.
  • The peer count is best treated as a health hint. For block-level liveness, prefer eth_blockNumber.