BitcoinMethods

getblockstats

The getblockstats RPC method allows you to calculate statistics for a specified block within a given window.

getblockstats

Overview

The 'getblockstats' RPC method allows you to calculate statistics for a specified block within a given window.

Request

shell

wget --no-check-certificate --quiet \
  --method POST \
  --timeout=0 \
  --header 'Content-Type: application/json' \
  --header 'accept: application/json' \
  --header 'X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY' \
  --body-data '{
  "jsonrpc": "1.0",
  "id": "1",
  "method": "getblockstats",
  "params": []
}' \'https://bitcoin-mainnet.node.coinapi.io'

csharp

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://bitcoin-mainnet.node.coinapi.io");
request.Headers.Add("accept", "application/json");
request.Headers.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY");
var content = new StringContent("{\r\n  \"jsonrpc\": \"1.0\",\r\n  \"id\": \"1\",\r\n  \"method\": \"getblockstats\",\r\n  \"params\": []\r\n}\r\n", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

php

<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json',
  'accept' => 'application/json',
  'X-CoinAPI-Key' => '73034021-THIS-IS-SAMPLE-KEY'
];
$body = '{
  "jsonrpc": "1.0",
  "id": "1",
  "method": "getblockstats",
  "params": []
}';
$request = new Request('POST', 'https://bitcoin-mainnet.node.coinapi.io', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
?>

python

import requests
import json

url = "https://bitcoin-mainnet.node.coinapi.io"

payload = json.dumps({
"jsonrpc": "1.0",
"id": "1",
"method": "getblockstats",
"params": []
})
headers = {
'Content-Type': 'application/json',
'accept': 'application/json',
'X-CoinAPI-Key': '73034021-THIS-IS-SAMPLE-KEY'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

javascript

var settings = {
  "url": "https://bitcoin-mainnet.node.coinapi.io",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/json",
    "accept": "application/json",
    "X-CoinAPI-Key": "73034021-THIS-IS-SAMPLE-KEY"
  },
  "data": JSON.stringify({
    "jsonrpc": "1.0",
    "id": "1",
    "method": "getblockstats",
    "params": []
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

go

package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

url := "https://bitcoin-mainnet.node.coinapi.io"
method := "POST"

payload := strings.NewReader(`{`+"
"+`
  "jsonrpc": "1.0",`+"
"+`
  "id": "1",`+"
"+`
  "method": "getblockstats",`+"
"+`
  "params": []`+"
"+`
}`+"
"+`
`)

client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)

if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("accept", "application/json")
req.Header.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")

res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

ruby

require "uri"
require "json"
require "net/http"

url = URI("https://bitcoin-mainnet.node.coinapi.io")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["accept"] = "application/json"
request["X-CoinAPI-Key"] = "73034021-THIS-IS-SAMPLE-KEY"
request.body = JSON.dump({
  "jsonrpc": "1.0",
  "id": "1",
  "method": "getblockstats",
  "params": []
})

response = https.request(request)
puts response.read_body

java

OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n  \"jsonrpc\": \"1.0\",\r\n  \"id\": \"1\",\r\n  \"method\": \"getblockstats\",\r\n  \"params\": []\r\n}\r\n");
Request request = new Request.Builder()
  .url("https://bitcoin-mainnet.node.coinapi.io")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("accept", "application/json")
  .addHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
  .build();
Response response = client.newCall(request).execute();

Request Parameters

'hash_or_height'

  • Type: string/numeric
  • Requirement: Mandatory
  • Description: The hash or height of the block you wish to target.

'stats'

  • Type: JSON Array
  • Requirement: Optional
  • Description: A JSON array that contains the values to be filtered from the statistics.

Response

{
  "avgfee": 0.00012345,
  "avgfeerate": 12.34,
  "avgtxsize": 250,
  "blockhash": "00000000000000000007d0f98d9ec3b757a2774e667e9b0d6437a1a9d70c1303",
  "feerate_percentiles": [5.67, 8.9, 12.34, 15.67, 19.01],
  "height": 680255,
  "ins": 1234,
  "maxfee": 0.00123456,
  "maxfeerate": 45.67,
  "maxtxsize": 800,
  "medianfee": 0.00009876,
  "mediantime": 1678391234,
  "mediantxsize": 225,
  "minfee": 0.00001234,
  "minfeerate": 4.56,
  "mintxsize": 150,
  "outs": 5678,
  "subsidy": 6.25,
  "swtotal_size": 1234567,
  "swtotal_weight": 12345678,
  "swtxs": 123,
  "time": 1678391234,
  "total_out": 123.45678901,
  "total_size": 1234567,
  "total_weight": 12345678,
  "totalfee": 0.01234567,
  "txs": 234,
  "utxo_increase": 123,
  "utxo_size_inc": 12345
}

The method returns a JSON object with the following properties:

  • avgfee: The average fee present in the block.
  • avgfeerate: The average fee rate in the block.
  • avgtxsize: The average transaction size in the block.
  • blockhash: The hash identifier of the block.
  • feerate_percentiles: A JSON array that contains the fee rates at the 10th, 25th, 50th, 75th, and 90th percentile weight units.
  • height: The height of the block in the blockchain.
  • ins: The total number of inputs in the block.
  • maxfee: The maximum fee found in the block.
  • maxfeerate: The maximum fee rate in the block.
  • maxtxsize: The maximum transaction size found in the block.
  • medianfee: The truncated median fee in the block.
  • mediantime: The median time past of the block.
  • mediantxsize: The truncated median transaction size in the block.
  • minfee: The minimum fee found in the block.
  • minfeerate: The minimum fee rate in the block.
  • mintxsize: The minimum transaction size in the block.
  • outs: The total number of outputs in the block.
  • subsidy: The subsidy of the block.
  • swtotal_size: The total size of all SegWit transactions in the block.
  • swtotal_weight: The total weight of all SegWit transactions in the block.
  • swtxs: The total number of SegWit transactions in the block.
  • time: The timestamp of the block.
  • total_out: The total amount in all outputs, excluding the coinbase and thus the reward (i.e., subsidy + total fee).
  • total_size: The total size of all non-coinbase transactions in the block.
  • total_weight: The total weight of all non-coinbase transactions in the block.
  • totalfee: The total fee accumulated in the block.
  • txs: The total number of transactions in the block.
  • utxo_increase: The increase or decrease in the number of unspent outputs.
  • utxo_size_inc: The increase or decrease in the size of the UTXO index.
Service StatusGitHub SDK