GetBlockTemplate & Stratum
GetBlockTemplate (GBT) Protocol: The Industry Standard for Block Construction
Miners do not interact directly with the database layers of Bitcoin Core while mining block headers. Instead, they run specialized consensus templates constructed by a full node. The communication protocol that governs this handoff is the GetBlockTemplate (GBT) protocol, standardized in BIP 22.
This guide details the GBT JSON-RPC data schema, the role of mining pool coordinators, and the evolution from Stratum V1 to Stratum V2.
📡 1. BIP 22 JSON-RPC: getblocktemplate
To construct a new candidate block, a mining client sends a JSON-RPC request to a trusted Bitcoin full node calling the getblocktemplate method.
The Raw JSON-RPC Request:
{
"jsonrpc": "1.0",
"id": "gbt_builder",
"method": "getblocktemplate",
"params": [{"rules": ["segwit"]}]
}
The JSON-RPC Response Payload:
The node compiles a raw candidate block structure from its active mempool and returns a detailed block template schema:
{
"version": 536870912,
"previousblockhash": "0000000000000000000201a4e1564f26db9b6426db4bf6ef4f1d4f2bd3f45f2c",
"transactions": [
{
"data": "01000000018f21e8a...",
"txid": "76df17332f...",
"hash": "76df17332f...",
"depends": [],
"fee": 12500,
"sigops": 1,
"weight": 564
}
],
"coinbaseaux": {
"flags": "062f503253482f"
},
"coinbasevalue": 312512500,
"longpollid": "0000000000000830390...",
"target": "00000000000000000003a3d50000000000000000000000000000000000000000",
"mintime": 1707865201,
"mutable": ["time", "transactions", "prevblock"],
"noncerange": "00000000ffffffff",
"sigoplimit": 20000,
"weightlimit": 4000000,
"curtime": 1707865500,
"bits": "1703a3d5",
"height": 830391
}
🗂️ 2. Critical Fields Explained
coinbasevalue: The total reward in Satoshis allocated for the coinbase output (Includes the active block subsidy, currently $3.125\text{ BTC}$, plus the total transaction fees $0.125\text{ BTC}$ collected).transactions: An ordered array of serialized transactions waiting in RAM. It lists raw hex bytes (data), fee metrics (fee), weight size (weight), and signature validation costs (sigops).depends: An array of indices mapping the unconfirmed in-block parent transactions that must be ordered before this specific transaction can validate.target/bits: The 256-bit mathematical threshold representing the leading-zero difficulty boundary the finalized block header hash must fall below.
⛏️ 3. The Evolution of Mining Coordination: GBT to Stratum
While GBT is perfect for solo miners running full nodes, its large JSON payload size makes it highly inefficient for large-scale mining pools coordinating millions of individual ASIC mining rigs.
MINING WORKER ORCHESTRATION LAYOUT
[ Bitcoin Full Node ]
│
▼ [getblocktemplate JSON-RPC]
[ Mining Pool Server (Coordinator) ]
│
├─► Distributes header work to ASICs via Stratum V1
├─► Re-builds templates and calculates Merkle Roots
│
├───► [ ASIC Worker 1 ] (Searches Nonce range A)
├───► [ ASIC Worker 2 ] (Searches Nonce range B)
└───► [ ASIC Worker 3 ] (Searches Nonce range C)
Stratum V1 (The Legacy Standard)
To bypass GBT's overhead, the Stratum V1 protocol was developed. Instead of transmitting the entire block template containing megabytes of raw transaction data to every ASIC rig:
1. The Pool Server runs a full node and compiles the block template using GBT.
2. The Pool Server calculates the Merkle Root branches.
3. The Pool Server sends only the 80-byte block header template and a portion of the Merkle branch to the ASIC rigs.
4. ASIC rigs only need to loop through the 4-byte nonce and a small extra-nonce space inside the coinbase, maximizing hash efficiency.
Stratum V2 (The Decentralization Upgrade)
While Stratum V1 is efficient, it introduces a major centralizing vulnerability: the pool server chooses which transactions get mined in the block template, allowing pools to censor or filter user transactions.
Stratum V2 resolves this by allowing individual ASIC miners to compile their own candidate block templates locally, while still sending their hashes to the mining pool coordinator to receive payouts. This restores censorship resistance back to individual miners, securing the network from single-point-of-failure pool controls.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: