getblocktemplate - Bitcoin

Example code for the getblocktemplate JSON-RPC method. Complete guide on how to use getblocktemplate JSON-RPC in GetBlock Web3 documentation.

This method returns data needed to construct a block to work on. It is used by miners to get a template for the next block.

Parameters

Parameter
Type
Required
Description

template_request

object

No

Template request parameters.

template_request.mode

string

No

Must be "template" or "proposal" (default: "template").

template_request.capabilities

array

No

Array of client capabilities (e.g., "longpoll", "coinbasetxn").

template_request.rules

array

No

Array of softfork rules to support.

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getblocktemplate",
    "params": [{"rules": ["segwit"]}],
    "id": "getblock.io"
}'

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "capabilities": ["proposal"],
        "version": 536870912,
        "rules": ["csv", "segwit", "taproot"],
        "vbavailable": {},
        "vbrequired": 0,
        "previousblockhash": "000000000000000000046b9302e08c16ea186950f42a5498320ddd1bd7ab3428",
        "transactions": [
            {
                "data": "0200000001...",
                "txid": "abc123...",
                "hash": "def456...",
                "depends": [],
                "fee": 25000,
                "sigops": 4,
                "weight": 900
            }
        ],
        "coinbaseaux": {"flags": ""},
        "coinbasevalue": 312500000,
        "longpollid": "000000000000000000046b9302e08c16ea186950f42a5498320ddd1bd7ab342812345",
        "target": "000000000000000000046b9302e08c16ea186950f42a5498000000000000000",
        "mintime": 1700000000,
        "mutable": ["time", "transactions", "prevblock"],
        "noncerange": "00000000ffffffff",
        "sigoplimit": 80000,
        "sizelimit": 4000000,
        "weightlimit": 4000000,
        "curtime": 1700001000,
        "bits": "170d21b9",
        "height": 820001,
        "default_witness_commitment": "6a24aa21a9ed..."
    }
}

Response Parameters

Field
Type
Description

version

number

Block version.

rules

array

Enabled softfork rules.

previousblockhash

string

Hash of current tip of the best chain.

transactions

array

Contents of non-coinbase transactions.

coinbaseaux

object

Data that should be included in coinbase scriptSig.

coinbasevalue

number

Maximum allowable coinbase value in satoshis.

target

string

The hash target.

mintime

number

Minimum timestamp appropriate for next block.

mutable

array

List of mutable template fields.

noncerange

string

Range of valid nonces.

sigoplimit

number

Limit of sigops per block.

sizelimit

number

Block size limit.

weightlimit

number

Block weight limit.

curtime

number

Current timestamp.

bits

string

Compressed target in compact format.

height

number

Height of the next block.

default_witness_commitment

string

Witness commitment for SegWit.

Use Case

The getblocktemplate method is essential for:

  • Mining pool software integration

  • Solo mining implementations

  • Block construction optimization

  • Mining software development

  • Testing mining configurations

  • Understanding block structure

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN.

-9

Node is downloading blocks

Initial block download in progress.

-10

Node is not connected

No peer connections available.

Integration Notes

The getblocktemplate method helps developers:

  • Build mining pool backends

  • Create solo mining software

  • Implement stratum proxies

  • Test block construction logic

  • Analyze transaction selection algorithms

Last updated

Was this helpful?