getpeerinfo - Zcash

This method returns information about each peer the node is connected to, including its address, advertised services, protocol version, user agent, and connection state.

Zebra returns fewer fields per peer than Bitcoin Core. Traffic counters such as bytessent and bytesrecv, and sync fields such as synced_blocks and startingheight, are not present.

Parameters

This method takes no parameters.

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getpeerinfo",
    "params": [],
    "id": "getblock.io"
}'

example.js

javascriptconst axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'getpeerinfo',
    params: [],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);

example.py

pythonimport requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'getpeerinfo',
        'params': [],
        'id': 'getblock.io'
    }
)

print(response.json())

example.rs

rustuse reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header("Content-Type", "application/json")
        .json(&json!({
            "jsonrpc": "2.0",
            "method": "getpeerinfo",
            "params": [],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;
    
    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "result": [
        {
            "addr": "168.119.7.215:8233",
            "services": "0000000000000001",
            "lastrecv": 1789744680,
            "inbound": false,
            "banscore": 0,
            "subver": "/Zebra:6.3.0/",
            "version": 170160,
            "connection_state": "connected",
            "pingtime": 0.051483004
        },
        {
            "addr": "65.109.86.46:8233",
            "services": "0000000000000001",
            "lastrecv": 1789744688,
            "inbound": false,
            "banscore": 0,
            "subver": "/Zakura:1.2.0/",
            "version": 170160,
            "connection_state": "connected",
            "pingtime": 0.032725716
        }
    ],
    "id": "getblock.io"
}

Response Parameters

ParameterTypeDescription
addrstringIP and port of the peer
servicesstringHex-encoded service bitmask
lastrecvintegerUnix timestamp of the last message received
pingtimenumberRound-trip ping time in seconds
versionintegerPeer's protocol version
subverstringPeer's user agent string
inboundbooleanWhether this is an inbound connection
banscoreintegerMisbehavior score
connection_statestringConnection state, such as connected

Use Cases

  • Peer Health Diagnostics: Detect stalled peers via lastrecv gaps and elevated pingtime
  • Client Diversity Monitoring: Track subver distribution to measure network client diversity
  • Ban Score Alerts: Alert on peers approaching the ban threshold (typically 100)
  • Connection State Debugging: Use connection_state to diagnose handshake failures

Error Handling

Error CodeMessageDescription
-32603Internal errorNode failed to enumerate peer state