getblockstats - Bitcoin Cash

This method computes per-block statistics for a block identified by hash or height. A subset of statistics can be requested to reduce computation.

Parameters

ParameterTypeRequiredDescription
hash_or_heightstring or numericYesBlock hash or height of the target block
statsarrayNoValues to return. Default is all values

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": "getblockstats",
    "params": [684634, null],
    "id": "getblock.io"
}'

example.js

javascriptconst axios = require('axios');
const { data } = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
  jsonrpc: '2.0', method: 'getblockstats',
  params: [684634, null], id: 'getblock.io'
});
console.log(data.result.avgfeerate, data.result.txs);

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': 'getblockstats',
        'params': [684634, null],
        'id': 'getblock.io'
    }
)

print(response.json()['result'])

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": "getblockstats",
            "params": [684634, null],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "error": null,
    "id": "getblock.io",
    "result": {
        "avgfee": 4520,
        "avgfeerate": 12,
        "avgtxsize": 445,
        "blockhash": "0000000000000000023a561e1ea370153aac5d1504726d1a039032831c05fcfc",
        "height": 684634,
        "ins": 4821,
        "maxfee": 182000,
        "maxfeerate": 220,
        "medianfee": 2260,
        "mediantime": 1617176373,
        "minfee": 500,
        "outs": 5932,
        "subsidy": 625000000,
        "time": 1617180599,
        "total_out": 284739201847,
        "total_size": 1252030,
        "totalfee": 12730055,
        "txs": 2815,
        "utxo_increase": 1111
    }
}

Response Parameters

ParameterTypeDescription
errornull|objectError object when the call fails, otherwise null
idstringRequest identifier matching the request
resultobjectObject of computed statistics for the block

Result Object

FieldTypeDescription
avgfeenumericAverage fee in the block, in satoshis
avgfeeratenumericAverage fee rate in satoshis per virtual byte
heightnumericBlock height
maxfeeratenumericMaximum fee rate in the block
subsidynumericBlock subsidy in satoshis
totalfeenumericTotal fees in the block, in satoshis
txsnumericNumber of transactions in the block

Use Cases

  • Fee Estimation: Derive recent fee-rate distributions from recent blocks
  • Block Analytics: Chart transaction counts and sizes over a height range
  • Subsidy Tracking: Read the block subsidy to model issuance across halvings
  • Capacity Studies: Measure UTXO set growth per block over time

Error Handling

Error CodeMessageDescription
-8Block height out of rangeThe requested height is negative or above the chain tip
-1Invalid parameter typeheight is not an integer
-32603Internal errorNode failed to read the block index