net_peerCount
The net_peerCount method returns the total number of network peers currently connected to your ZetaChain node. This metric is crucial for understanding your node's level of network participation and its ability to synchronize blockchain data effectively across ZetaChain's unique omnichain architecture.
A healthy peer count indicates strong network connectivity and ensures your node receives timely updates about new blocks, transactions, cross-chain messages, and network events. For ZetaChain's omnichain functionality, maintaining adequate peer connections is essential for proper consensus participation and efficient cross-chain communication that bridges Bitcoin, Ethereum, and other connected chains.
The peer count directly impacts your node's reliability, data synchronization speed, cross-chain message relay performance, and overall contribution to network decentralization. Monitoring this metric helps identify network isolation issues, firewall problems, or configuration errors that might prevent optimal node performance in ZetaChain's multi-chain ecosystem.
Parameters
No parameters required. This method provides a simple count of active peer connections.
{
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": 1
}
Returns
QUANTITY - Hexadecimal value representing the number of currently connected peers. Must be converted to decimal for human-readable format.
Use Cases
- Network Health Dashboards: Display real-time peer connectivity metrics in monitoring dashboards
- Connection Quality Assessment: Evaluate whether the node has sufficient peer connections for reliable operation
- Isolation Detection: Identify nodes that have become isolated from the network due to configuration issues
- Performance Optimization: Correlate peer count with sync speed to optimize node configuration
- Cross-Chain Relay Monitoring: Ensure adequate connectivity for cross-chain message propagation
- Automated Scaling: Trigger infrastructure scaling based on peer connection patterns
Best Practices for Production
- Maintain at least 10-25 peers for reliable network participation
- Alert when peer count drops below minimum thresholds (e.g., less than 5 peers)
- Monitor peer count trends over time to identify gradual degradation
- Combine with sync status checks to ensure connected peers are providing valid data
- Review firewall rules and port configurations if peer count remains consistently low
- Consider using static peers or bootnodes for guaranteed initial connections
- Implement exponential backoff for peer count checks to reduce unnecessary load
Integration with Web3 Libraries
Using ethers.js
import { JsonRpcProvider } from 'ethers';
const provider = new JsonRpcProvider('https://zetachain-evm.blockpi.network/v1/rpc/public');
async function monitorPeerConnections() {
try {
const hexPeerCount = await provider.send('net_peerCount', []);
const peerCount = parseInt(hexPeerCount, 16);
console.log(`Currently connected to ${peerCount} ZetaChain peers`);
if (peerCount < 5) {
console.warn('Low peer count detected. Node may be isolated.');
} else if (peerCount > 50) {
console.log('Excellent network connectivity for omnichain operations');
}
return peerCount;
} catch (error) {
console.error('Failed to retrieve peer count:', error);
return 0;
}
}
// Monitor continuously
setInterval(async () => {
const peers = await monitorPeerConnections();
// Send to monitoring system
}, 30000); // Check every 30 seconds
Using web3.js
import Web3 from 'web3';
const web3 = new Web3('https://zetachain-evm.blockpi.network/v1/rpc/public');
async function getPeerMetrics() {
const peerCount = await web3.eth.net.getPeerCount();
console.log(`Active ZetaChain peers: ${peerCount}`);
const [listening, networkId] = await Promise.all([
web3.eth.net.isListening(),
web3.eth.net.getId()
]);
return {
peers: peerCount,
listening,
networkId,
timestamp: new Date().toISOString()
};
}
Example Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x19"
}
The hexadecimal value 0x19 equals 25 in decimal, indicating 25 connected peers.
Related Methods
- net_listening - Check if the node is listening for connections
- net_version - Get the network ID to verify correct network
- eth_syncing - Check synchronization status