getblocktemplate - Bitcoin Cash

This method returns data needed to construct a block to work on, following the getblocktemplate mining protocol. It is used by mining software to assemble candidate blocks.

Parameters

ParameterTypeRequiredDescription
template_requestobjectNoObject specifying template mode, capabilities, and supported rules

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": "getblocktemplate",
    "params": [{"rules": ["csv", "segwit"]}],
    "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: 'getblocktemplate',
  params: [{ rules: ['csv', 'segwit'] }], id: 'getblock.io'
});
console.log(data.result.height, data.result.target);

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': 'getblocktemplate',
        'params': [{"rules": ["csv", "segwit"]}],
        '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": "getblocktemplate",
            "params": [{"rules": ["csv", "segwit"]}],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;

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

Response

json{
    "error": null,
    "id": "getblock.io",
    "result": {
        "version": 536870912,
        "previousblockhash": "0000000000000000023a561e1ea370153aac5d1504726d1a039032831c05fcfc",
        "height": 684635,
        "curtime": 1617180999,
        "bits": "170cdf6f",
        "target": "000000000000000000073da8...",
        "coinbasevalue": 625000000,
        "mintime": 1617176374,
        "sizelimit": 32000000,
        "transactions": []
    }
}

Response Parameters

ParameterTypeDescription
errornull|objectError object when the call fails, otherwise null
idstringRequest identifier matching the request
resultobjectBlock template object for mining

Result Object

FieldTypeDescription
versionnumericBlock version
previousblockhashstringHash of the current tip to build on
heightnumericHeight of the block to be mined
coinbasevaluenumericMaximum coinbase value in satoshis
targetstringThe proof-of-work target as a hex string
transactionsarrayTransactions to include in the block

Use Cases

  • Mining Software: Feed block templates into a mining worker
  • Pool Operation: Assemble candidate blocks for pool participants
  • Coinbase Construction: Read coinbasevalue to build the coinbase transaction
  • Template Monitoring: Track template changes as the mempool updates

Error Handling

Error CodeMessageDescription
-32700Parse errorRequest body is not valid JSON
-32600Invalid requestThe JSON sent is not a valid request object
-32603Internal errorNode failed to read the requested chain state