net_peerCount - BSC
This method returns the number of peers currently connected to the client on the BNB Smart Chain network.
Parameters
- None
Request Example
cURL
bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": "getblock.io"
}'JavaScript (Axios)
javascriptconst axios = require('axios');
const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
method: 'net_peerCount',
params: [],
id: 'getblock.io'
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => {
const peerCount = parseInt(response.data.result, 16);
console.log('Peer Count:', peerCount);
})
.catch(error => console.error(error));Python
pythonimport requests
url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
payload = {
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": "getblock.io"
}
response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
peer_count = int(response.json()["result"], 16)
print(f"Peer Count: {peer_count}")Rust
rustuse reqwest::Client;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let payload = json!({
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": [],
"id": "getblock.io"
});
let response = client
.post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
.header("Content-Type", "application/json")
.json(&payload)
.send()
.await?;
let result: serde_json::Value = response.json().await?;
println!("{:#?}", result);
Ok(())
}Response Example
response.json
json{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": "0x19"
}Response Parameters
| Parameter | Type | Description |
|---|---|---|
| result | string | Peer count in hex (0x19 = 25) |
Use Cases
- Monitor node connectivity
- Check network health
- Debug connection issues
Error Handling
-32603
Internal error
SDK Integration
Ethers.js
javascriptconst { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');
const peerCount = await provider.send('net_peerCount', []);
console.log('Peer Count:', parseInt(peerCount, 16));Viem
javascriptimport { createPublicClient, http } from 'viem';
import { bsc } from 'viem/chains';
const client = createPublicClient({
chain: bsc,
transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});
const peerCount = await client.request({ method: 'net_peerCount' });
console.log('Peer Count:', parseInt(peerCount, 16));