1. 前言
在比特幣挖礦領域,大部分礦工會直接連上礦池。但有些情境下,我們希望:
- 礦工本身不連網(安全隔離、內網環境)
- 透過中介主機與礦池交互,負責分派挖礦任務
- 自行設計「任務分配 + 計算回傳」的流程
本文將以 CKpool Solo Mining 為例,介紹如何用一台連網主機協調兩台離線礦工參與主網挖礦,並搭配 watch-only 冷錢包 安全收款。
2. 架構流程圖

Step 1 — 建立 Watch-only 冷錢包
- 使用 Electrum(或其他支援 watch-only 的錢包)
- 在冷端(離線)生成助記詞 → 導出
xpub
- 在熱端(連網)匯入
xpub
建立 watch-only 錢包 - 用此錢包的地址作為 CKpool 挖礦收款地址
Step 2 — 連接 CKpool
- CKpool 連線格式:
bfgminer -o stratum+tcp://solo.ckpool.org:3333 -u <BTC地址> -p x
Step 3 — 建立模擬任務分派器
中介主機 Python 範例(簡化版):
import requests
WORKERS = ["http://192.168.1.11:8000/hash", "http://192.168.1.12:8000/hash"]
BLOCK_HEADER = "abcd..." # 從 CKpool 取得
TARGET = "00000000ffff..." # 從 CKpool 取得
def assign_work():
nonce_start = 0
nonce_step = 50000
for worker in WORKERS:
data = {
"block_header": BLOCK_HEADER,
"start_nonce": nonce_start,
"end_nonce": nonce_start + nonce_step,
"target": TARGET
}
r = requests.post(worker, json=data)
print(worker, r.json())
nonce_start += nonce_step + 1
if __name__ == "__main__":
assign_work()
Step 4 — 離線礦工 Flask API
from flask import Flask, request, jsonify
import hashlib
app = Flask(__name__)
def double_sha256(b: bytes) -> bytes:
return hashlib.sha256(hashlib.sha256(b).digest()).digest()
@app.route('/hash', methods=['POST'])
def hash_nonce_range():
header_hex = request.json['block_header']
start_nonce = int(request.json['start_nonce'])
end_nonce = int(request.json['end_nonce'])
target = int(request.json['target'], 16)
base_header = bytes.fromhex(header_hex)
for nonce in range(start_nonce, end_nonce):
nonce_bytes = nonce.to_bytes(4, 'little')
full_header = base_header[:-4] + nonce_bytes
hash_result = double_sha256(full_header)
if int.from_bytes(hash_result, 'big') < target:
return jsonify({'found': True, 'nonce': nonce, 'hash': hash_result.hex()})
return jsonify({'found': False})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
4. 範例配置檔(假設 LAN 網段為 192.168.1.0/24)
中介主機 config.json
{
"ckpool_url": "stratum+tcp://solo.ckpool.org:3333",
"btc_address": "你的BTC收款地址",
"workers": [
"http://192.168.1.11:8000/hash",
"http://192.168.1.12:8000/hash"
],
"nonce_step": 50000
}
離線礦工啟動命令
python worker_api.py
5. CKpool 限制與角色
- 你只是「雜湊接單工人」
- 無法自行簽名並廣播區塊
- 成功找到 nonce 後由 CKpool 打包並廣播
- 區塊獎勵直接送到你設定的地址
6. 結語
透過這種架構,你可以:
- 在安全隔離的情況下利用離線礦工算力
- 中介主機負責與礦池交互
- 模組化架構,方便日後擴充或換協定(HTTP → WebSocket / TCP)