getblocktemplate - Zcash

This method returns a template for constructing a candidate block for mining. Miners and mining pools call this to receive the current block header parameters, coinbase output structure, and the set of mempool transactions that should be included. Zcash uses the Equihash proof-of-work algorithm, so template consumers need to solve the Equihash puzzle for the provided parameters.

Parameters

ParameterTypeRequiredDescription
template_requestobjectNoTemplate request parameters (see below). Defaults to the standard template request

Template Request

FieldTypeRequiredDescription
modestringNotemplate (default) requests a new template; proposal submits a proposed block
capabilitiesarray of stringNoClient capabilities (coinbasetxn, coinbasevalue, proposal)
longpollidstringNoLong-polling ID for waiting on updated templates

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": [
        {
            "mode": "template",
            "capabilities": [
                "coinbasetxn",
                "coinbasevalue"
            ]
        }
    ],
    "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: 'getblocktemplate',
    params: [
        {
            "mode": "template",
            "capabilities": [
                "coinbasetxn",
                "coinbasevalue"
            ]
        }
    ],
    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': 'getblocktemplate',
        'params': [
        {
            "mode": "template",
            "capabilities": [
                "coinbasetxn",
                "coinbasevalue"
            ]
        }
    ],
        '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": "getblocktemplate",
            "params": [
        {
            "mode": "template",
            "capabilities": [
                "coinbasetxn",
                "coinbasevalue"
            ]
        }
    ],
            "id": "getblock.io"
        }))
        .send()
        .await?
        .json::<Value>()
        .await?;
    
    println!("Result: {}", response["result"]);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "capabilities": [
            "proposal"
        ],
        "version": 4,
        "previousblockhash": "00000000000f3c0bdf81aba0bf081c5c4882975cbc0a8ce35e70ddb5f265f1b1",
        "blockcommitmentshash": "5eae9c5cbe0e8d3e2f5cd8b0a4e3b1f2c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4",
        "lightclientroothash": "3a2b1c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b",
        "finalsaplingroothash": "01a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1",
        "defaultroots": {
            "merkleroot": "80d21f43485fb5aed2bcb011a00fb70776b2f6b4ba05722dbf2dce6f53fc410f",
            "chainhistoryroot": "b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3",
            "authdataroot": "80d21f43485fb5aed2bcb011a00fb70776b2f6b4ba05722dbf2dce6f53fc410f"
        },
        "transactions": [],
        "coinbasetxn": {
            "data": "0400008085202f890100000000000000000000000000000000...",
            "hash": "2b1c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b09",
            "authdigest": "0000000000000000000000000000000000000000000000000000000000000000",
            "depends": [],
            "fee": 0,
            "sigops": 0,
            "required": true
        },
        "longpollid": "00000000000f3c0bdf81aba0bf081c5c4882975cbc0a8ce35e70ddb5f265f1b1-47",
        "target": "00000000005cea00000000000000000000000000000000000000000000000000",
        "mintime": 1747852500,
        "mutable": [
            "time",
            "transactions",
            "prevblock"
        ],
        "noncerange": "00000000ffffffff",
        "sigoplimit": 20000,
        "sizelimit": 2000000,
        "curtime": 1747852800,
        "bits": "1d00ffff",
        "height": 2856343
    }
}

This method does not work on shared endpoints. Zebra only builds a block template when the node is configured with a miner address, and shared nodes are not. The request returns:

json{
    "code": 0,
    "message": "miner parameters are required for get_block_template"
}

The response above shows the template format for a node you operate yourself with mining configured.

Response Parameters

ParameterTypeDescription
versionintegerBlock version to use
previousblockhashstringHash of the parent block
blockcommitmentshashstringBlock commitments hash to include in the header
finalsaplingroothashstringFinal Sapling root at this block height
defaultrootsobjectPrecomputed default root hashes for header construction
transactionsarray of objectMempool transactions selected for inclusion
coinbasetxnobjectCoinbase transaction template with reward split
targetstringDifficulty target to solve for
mintimeintegerMinimum allowed block timestamp
mutablearray of stringFields the miner may modify
noncerangestringNonce range hint
sigoplimitintegerMaximum signature operations allowed in the block
sizelimitintegerMaximum block size in bytes
curtimeintegerCurrent timestamp suggested by the node
bitsstringCompact difficulty target
heightintegerHeight at which this block will be included

Use Cases

  • Solo Mining: Miners request templates to construct candidate blocks for Equihash solving
  • Mining Pool Coordination: Pool servers fetch templates and distribute solving work to participant miners
  • Block Proposal Verification: Submit constructed blocks in proposal mode to check validity before broadcasting
  • Long-Poll Template Updates: Use longpollid to wait for new templates when the chain tip advances

Error Handling

Error CodeMessageDescription
-8Invalid parameterTemplate request parameters are malformed
-32602Invalid paramsTemplate request structure is invalid
-32603Internal errorNode failed to build the template