bitcoin-cli 常用指令大全
查詢區塊餘額廣播交易,完整指令範例與輸出解說。
bitcoin-cli 指令大全:比特幣開發者實戰指南
比特幣 CLI(Command Line Interface)是 Bitcoin Core 提供的命令行工具,也是比特幣開發者、節點運營商和進階用戶最直接、最靈活的操作介面。與圖形化錢包不同,bitcoin-cli 提供了對比特幣網路的完整控制能力,從查詢區塊數據、構造交易、管理錢包到節點監控,都能透過指令完成。本文提供 50+ 常用指令的完整範例與輸出解說,並包含腳本自動化與常見錯誤處理。
bitcoin-cli 基礎設定與環境
連線比特幣節點
bitcoin-cli 需要一個運行的 Bitcoin Core 節點作為後端。預設情況下,bitcoin-cli 透過 RPC(Remote Procedure Call)連線到本機節點的 8332 端口(主網)或 18332 端口(測試網)。
# 連線到本機節點(預設)
bitcoin-cli getblockchaininfo
# 連線到遠端節點
bitcoin-cli -rpcconnect=192.168.1.100 -rpcport=8332 getblockchaininfo
# 使用測試網
bitcoin-cli -testnet getblockchaininfo
# 使用.signet(比特幣簽名網路)
bitcoin-cli -signet getblockchaininfo
# 使用 regtest(本地測試網路)
bitcoin-cli -regtest getblockchaininfo
認證方式
Bitcoin Core RPC 支援兩種認證方式:Cookie 認證和帳號密碼認證。
# 使用帳號密碼(透過環境變數)
export BITCOIN_RPC_USER="rpcuser"
export BITCOIN_RPC_PASSWORD="rpcpassword"
bitcoin-cli getblockchaininfo
# 使用帳號密碼(直接指定)
bitcoin-cli -rpcuser=rpcuser -rpcpassword=rpcpassword getblockchaininfo
# 使用 cookie 檔案(自動產生的認證方式)
# 預設位置:~/.bitcoin/.cookie
bitcoin-cli -rpccookiefile=~/.bitcoin/.cookie getblockchaininfo
常見配置參數
bitcoin-cli 的行為可以通過多種方式配置:
# 指定 RPC bind 地址
bitcoin-cli -rpcbind=127.0.0.1:8332
# 指定 Wallet 名稱(如果有多個錢包)
bitcoin-cli -wallet=my_wallet getwalletinfo
# 設定輸出格式(預設為 JSON)
bitcoin-cli -getinfo getblockchaininfo # JSON 格式
bitcoin-cli getblockchaininfo # JSON 格式
# 設定交易費用率單位(sat/vB 或 BTC/kvB)
bitcoin-cli -feeEstimatesMode=sat/vB estimatesmartfee 6
區塊鏈查詢指令
getblockchaininfo:區塊鏈狀態總覽
這是最常用的區塊鏈查詢指令,可以快速了解比特幣網路的整體狀態。
bitcoin-cli getblockchaininfo
輸出範例:
{
"chain": "main",
"blocks": 876543,
"headers": 876543,
"bestblockhash": "0000000000000000000abf0bcf9085ea7d0a19dbab9c7e0b06ba19c79f4c3a5d",
"difficulty": 89038504876543.12,
"mediantime": 1708000000,
"verificationprogress": 0.999998,
"initialblockdownload": false,
"chainwork": "0000000000000000000000000000000000000000276d9ec3a0c3f7d7c9f0c0c0c",
"size_on_disk": 565432100000,
"pruned": false,
"softforks": {
"bip34": {"status": "active"},
"bip66": {"status": "active"},
"bip65": {"status": "active"},
"csv": {"status": "active"},
"segwit": {"status": "active"},
"taproot": {"status": "active"}
},
"warnings": ""
}
getblock:區塊詳細資訊
查詢特定區塊的完整資訊,包括交易列表、區塊大小、時間戳記等。
# 透過區塊高度查詢
bitcoin-cli getblock 876543
# 透過區塊雜湊查詢
bitcoin-cli getblock 0000000000000000000abf0bcf9085ea7d0a19dbab9c7e0b06ba19c79f4c3a5d
# 只獲取區塊雜湊(輕量級查詢)
bitcoin-cli getblockhash 876543
# 獲取區塊頭資訊(不包含交易)
bitcoin-cli getblockheader 876543
getblockcount 與 getbestblockhash:節點同步狀態
這兩個指令是監控節點同步狀態的核心工具。
# 查詢已同步的區塊數量
bitcoin-cli getblockcount
# 查詢最新區塊的雜湊
bitcoin-cli getbestblockhash
# 組合使用:檢查節點是否正常同步
BLOCK_COUNT=$(bitcoin-cli getblockcount)
BEST_HASH=$(bitcoin-cli getbestblockhash)
echo "Current block: $BLOCK_COUNT"
echo "Best block hash: $BEST_HASH"
getmempoolinfo:記憶池狀態
記憶池(Mempool)是比特幣網路中待確認交易的暫存區,了解記憶池狀態對估計交易費用非常重要。
bitcoin-cli getmempoolinfo
輸出範例:
{
"loaded": true,
"size": 125430,
"bytes": 52430000,
"usage": 104800000,
"total_fee": 2.543,
"maxmempool": 300000000,
"mempoolminfee": 0.00001000,
"minrelaytxfee": 0.00001000,
"unbroadcastcount": 0
}
getrawmempool:記憶池交易列表
# 獲取記憶池所有交易 ID(輕量模式)
bitcoin-cli getrawmempool
# 獲取完整交易資訊
bitcoin-cli getrawmempool true
# 只獲取交易 ID(不包含詳細資訊)
bitcoin-cli getrawmempool false
# 獲取記憶池的費用估算
bitcoin-cli getrawmempool true | jq '[.[] | {fee: .fee, vsize: .vsize}] | sort_by(.fee) | reverse | .[:10]'
交易查詢指令
getrawtransaction:查詢原始交易
比特幣區塊鏈上的所有交易都可以透過交易 ID(TXID)查詢。
# 查詢交易(需要交易解碼資訊)
bitcoin-cli getrawtransaction a1b2c3d4e5f6... true
# 只獲取交易的十六進制原始資料
bitcoin-cli getrawtransaction a1b2c3d4e5f6...
# 查詢交易的區塊確認資訊
# 預設 verbose=false,設為 true 可獲取詳細資訊
bitcoin-cli getrawtransaction a1b2c3d4e5f6... true
輸出範例(verbose 模式):
{
"txid": "a1b2c3d4e5f6g7h8i9j0...",
"hash": "a1b2c3d4e5f6g7h8i9j0...",
"version": 2,
"size": 225,
"vsize": 144,
"weight": 576,
"locktime": 876543,
"vin": [
{
"txid": "previous_txid...",
"vout": 0,
"scriptSig": {
"asm": "OP_DUP OP_HASH160 ... OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914..."
},
"sequence": 4294967293
}
],
"vout": [
{
"value": 0.04990000,
"n": 0,
"scriptPubKey": {
"asm": "OP_HASH160 ... OP_EQUAL",
"hex": "a914...",
"reqSigs": 1,
"type": "scripthash",
"addresses": ["3F7..."]
}
}
],
"blockhash": "0000000000000000000...",
"confirmations": 6,
"time": 1708000000,
"blocktime": 1708000000
}
decoderawtransaction:解碼原始交易
當你擁有交易的十六進制資料時,可以解碼查看交易內容。
# 解碼原始交易
bitcoin-cli decoderawtransaction 02000000000101000000000000000000000000000000000000000000000000000000000000ffffffff...
decodescript:解碼腳本
# 解碼腳本(包括輸出腳本和輸入腳本)
bitcoin-cli decodescript a91487f6e8a9...
費用估算指令
estimatesmartfee:智慧費用估算
這是 Bitcoin Core 提供的費用估算功能,會根據網路擁塞情況自動計算建議的費用率。
# 估算 6 個區塊確認的費用率
bitcoin-cli estimatesmartfee 6
# 估算 3 個區塊確認的費用率
bitcoin-cli estimatesmartfee 3
# 估算保守模式的費用率
bitcoin-cli estimatesmartfee 6 "conservative"
輸出範例:
{
"feerate": 0.00002100,
"units": "sat/vB",
"estconfirmations": 6
}
estimatefee:簡單費用估算(已棄用)
# 舊版語法,僅用於向後相容
bitcoin-cli estimatefee 6
paytxfee:設定交易費用率
# 設定節點廣播交易的預設費用率(BTC/kvB)
bitcoin-cli paytxfee 0.00001
# 查詢當前設定
bitcoin-cli getwalletinfo | grep -i paytxfee
# 設定每 KB 的 satoshi 數量
# 例如:10 sat/vB = 0.00001 BTC/kvB
bitcoin-cli paytxfee 0.00001
錢包管理指令
getwalletinfo:錢包狀態總覽
bitcoin-cli getwalletinfo
輸出範例:
{
"walletname": "my_wallet",
"walletversion": 169900,
"balance": 1.23456789,
"unconfirmed_balance": 0.00000000,
"immature_balance": 0.00000000,
"txcount": 150,
"keypoololdest": 1705000000,
"keypoolsize": 1000,
"keypoolsize_hd_internal": 1000,
"paytxfee": 0.00001000,
"private_keys_enabled": true,
"avoid_reuse": false,
"scanning": false,
"descriptors": true
}
getnewaddress:生成新地址
比特幣地址是錢包接收資金的基礎,正確管理地址對隱私和安全都很重要。
# 生成新地址(預設:P2PKH)
bitcoin-cli getnewaddress
# 生成 P2SH 格式地址(相容 SegWit)
bitcoin-cli getnewaddress "" "p2sh-segwit"
# 生成原生隔離見證地址(Bech32)
bitcoin-cli getnewaddress "" "bech32"
# 生成 Taproot 地址(比特幣升級後)
bitcoin-cli getnewaddress "" "bech32m"
# 生成帶標籤的地址(用於識別)
bitcoin-cli getnewaddress "donation" "bech32"
listunspent:查詢未花費輸出
UTXO(Unspent Transaction Output)是比特幣餘額的基本單位,這個指令可以查詢錢包中所有可花費的 UTXO。
# 查詢所有未花費輸出
bitcoin-cli listunspent
# 查詢特定地址的未花費輸出
bitcoin-cli listunspent 6 9999999 ["bc1q..."]
# 查詢最小確認數的未花費輸出
bitcoin-cli listunspent 1
# 查詢最大金額的未花費輸出
bitcoin-cli listunspent 0 9999999 [] 999999
listtransactions:交易歷史
# 查詢最近 10 筆交易
bitcoin-cli listtransactions "*" 10
# 查詢最近 20 筆交易,跳過前 10 筆
bitcoin-cli listtransactions "*" 20 10
# 查詢特定帳戶的交易
bitcoin-cli listtransactions "my_account"
# 查詢包含特定地址的交易
bitcoin-cli listtransactions "*" 100 0 false "bc1q..."
交易構造與廣播
createmultisig:創建多簽地址
多簽地址需要多個私鑰授權才能花費比特幣,常用於共享資金或增加安全性。
# 創建 2-of-3 多簽地址
bitcoin-cli createmultisig 2 '["pubkey1", "pubkey2", "pubkey3"]'
# 創建 P2SH 格式的多簽地址
bitcoin-cli createmultisig 2 '["pubkey1", "pubkey2", "pubkey3"]' "legacy"
# 創建 P2WSH 格式的多簽地址(隔離見證)
bitcoin-cli createmultisig 2 '["pubkey1", "pubkey2", "pubkey3"]' "bech32"
createpsbt:創建 Partially Signed Bitcoin Transaction
PSBT 是比特幣交易構造的標準格式,支援多方協作簽名。
# 基本 PSBT 創建
bitcoin-cli createpsbt '[{"txid":"...","vout":0,"amount":0.5}]' '[{"address":"bc1q...","amount":0.4}]'
# 創建帶有找零地址的 PSBT
bitcoin-cli createpsbt \
'[{"txid":"a1b2c3d4...","vout":1,"amount":1.0}]' \
'[{"bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh":"0.8"}]' \
0 \
'{"includeWatching":true}'
walletprocesspsbt:處理 PSBT 簽名
# 對 PSBT 進行簽名
bitcoin-cli walletprocesspsbt "psbt_base64_string"
# 使用完整簽名模式
bitcoin-cli walletprocesspsbt "psbt_base64_string" true "ALL"
signrawtransactionwithwallet:錢包簽名
# 使用錢包私鑰簽名交易
bitcoin-cli signrawtransactionwithwallet "raw_tx_hex"
# 簽名並指定簽名類型
bitcoin-cli signrawtransactionwithwallet "raw_tx_hex" [] "ALL|ANYONECANPAY|SINGLE|FINAL"
sendrawtransaction:廣播交易
# 廣播已簽名的交易
bitcoin-cli sendrawtransaction "signed_tx_hex"
# 廣播並設定最高費用(避免費用過高)
bitcoin-cli sendrawtransaction "signed_tx_hex" 0.0001
# 允許費用低於節點設定的最低費用
bitcoin-cli sendrawtransaction "signed_tx_hex" 0 false true
節點網路指令
getnetworkinfo:網路節點資訊
bitcoin-cli getnetworkinfo
輸出範例:
{
"version": 27000100,
"subversion": "/Satoshi:27.0.1/",
"protocolversion": 70015,
"localservices": "0000000000000409",
"localservicesnames": ["NETWORK", "WITNESS", "STNEMP"],
"localrelay": true,
"timeoffset": 0,
"networkactive": true,
"connections": 18,
"networks": [
{
"name": "ipv4",
"limited": false,
"reachable": true,
"proxy": "",
"score": 24
}
],
"relayfee": 0.00001000,
"incrementalfee": 0.00000100,
"warning": ""
}
getpeerinfo:對等節點資訊
# 獲取所有連接的節點資訊
bitcoin-cli getpeerinfo
# 獲取節點資訊並按連接時間排序
bitcoin-cli getpeerinfo | jq -s '.[] | {id, addr, version, bytesrecv_per_msg_name, bytessent_per_msg_name}'
addnode:節點管理
# 新增節點到連接列表
bitcoin-cli addnode "123.456.78.90:8333" "add"
# 移除節點
bitcoin-cli addnode "123.456.78.90:8333" "remove"
# 嘗試連接到節點一次
bitcoin-cli addnode "123.456.78.90:8333" "onetry"
# 列出所有已連接的節點
bitcoin-cli getaddednodeinfo
disconnectnode:斷開連接
# 斷開特定節點
bitcoin-cli disconnectnode "123.456.78.90:8333"
# 斷開所有節點(謹慎使用)
bitcoin-cli disconnectnode ""
進階指令與腳本實作
使用 bitcoin-cli 進行自動化腳本
以下是一個完整的比特幣餘額查詢腳本,展示了如何將 bitcoin-cli 整合到自動化流程中。
#!/bin/bash
# bitcoin_balance_check.sh - 比特幣餘額查詢腳本
set -euo pipefail
# 配置
RPC_USER="${RPC_USER:-rpcuser}"
RPC_PASSWORD="${RPC_PASSWORD:-rpcpassword}"
RPC_HOST="${RPC_HOST:-127.0.0.1}"
RPC_PORT="${RPC_PORT:-8332}"
# 餘額查詢函數
get_balance() {
local address="$1"
bitcoin-cli -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASSWORD" \
-rpchost="$RPC_HOST" -rpcport="$RPC_PORT" \
getbalance
}
# 查詢特定地址的餘額(需要錢包導入地址)
get_address_balance() {
local address="$1"
bitcoin-cli -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASSWORD" \
-rpchost="$RPC_HOST" -rpcport="$RPC_PORT" \
getreceivedbyaddress "$address" 0
}
# 主執行流程
main() {
echo "比特幣節點餘額查詢"
echo "=================="
# 查詢錢包總餘額
balance=$(get_balance "*")
echo "錢包餘額: $balance BTC"
# 查詢未確認餘額
unconfirmed=$(bitcoin-cli -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASSWORD" \
-rpchost="$RPC_HOST" -rpcport="$RPC_PORT" \
getunconfirmedbalance)
echo "未確認餘額: $unconfirmed BTC"
# 查詢節點狀態
block_count=$(bitcoin-cli -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASSWORD" \
-rpchost="$RPC_HOST" -rpcport="$RPC_PORT" \
getblockcount)
echo "同步區塊高度: $block_count"
# 查詢連接數
connections=$(bitcoin-cli -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASSWORD" \
-rpchost="$RPC_HOST" -rpcport="$RPC_PORT" \
getconnectioncount)
echo "連接節點數: $connections"
}
main "$@"
Python 整合 bitcoin-cli
以下範例展示如何使用 Python 與 bitcoin-cli 進行互動。
#!/usr/bin/env python3
"""
比特幣 RPC 客戶端類別
使用 subprocess 呼叫 bitcoin-cli
"""
import subprocess
import json
import os
from typing import Any, Optional, Dict
class BitcoinRPC:
"""比特幣 RPC 客戶端封裝"""
def __init__(
self,
rpc_user: str = "rpcuser",
rpc_password: str = "rpcpassword",
rpc_host: str = "127.0.0.1",
rpc_port: int = 8332,
wallet_name: Optional[str] = None
):
self.rpc_user = rpc_user
self.rpc_password = rpc_password
self.rpc_host = rpc_host
self.rpc_port = rpc_port
self.wallet_name = wallet_name
def _build_command(self, method: str, *params) -> list:
"""建構 bitcoin-cli 命令"""
cmd = [
"bitcoin-cli",
"-rpcuser", self.rpc_user,
"-rpcpassword", self.rpc_password,
"-rpchost", self.rpc_host,
"-rpcport", str(self.rpc_port)
]
if self.wallet_name:
cmd.extend(["-wallet", self.wallet_name])
cmd.append(method)
cmd.extend(params)
return cmd
def call(self, method: str, *params) -> Any:
"""執行 RPC 呼叫"""
cmd = self._build_command(method, *params)
try:
result = subprocess.run(
cmd,
capture_output=True,
text=True,
check=True
)
if result.stdout.strip():
return json.loads(result.stdout)
return None
except subprocess.CalledProcessError as e:
print(f"RPC 錯誤: {e.stderr}")
raise
except json.JSONDecodeError:
return result.stdout.strip()
# 便捷方法
def get_balance(self) -> float:
"""獲取錢包餘額"""
return self.call("getbalance")
def get_new_address(self, account: str = "", address_type: str = "bech32") -> str:
"""生成新地址"""
return self.call("getnewaddress", account, address_type)
def send_to_address(self, address: str, amount: float) -> str:
"""發送比特幣到指定地址"""
return self.call("sendtoaddress", address, str(amount))
def get_blockchain_info(self) -> Dict:
"""獲取區塊鏈資訊"""
return self.call("getblockchaininfo")
def get_mempool_info(self) -> Dict:
"""獲取記憶池資訊"""
return self.call("getmempoolinfo")
def get_transaction(self, txid: str, verbose: bool = True) -> Dict:
"""獲取交易詳情"""
return self.call("getrawtransaction", txid, str(verbose).lower())
def list_unspent(self, min_confirmations: int = 0) -> list:
"""列出未花費輸出"""
return self.call("listunspent", str(min_confirmations))
def estimate_smart_fee(self, conf_target: int = 6) -> Dict:
"""估算智慧費用"""
return self.call("estimatesmartfee", str(conf_target))
def get_network_info(self) -> Dict:
"""獲取網路資訊"""
return self.call("getnetworkinfo")
def get_wallet_info(self) -> Dict:
"""獲取錢包資訊"""
return self.call("getwalletinfo")
def list_transactions(self, count: int = 10, skip: int = 0) -> list:
"""列出交易歷史"""
return self.call("listtransactions", "*", str(count), str(skip))
# 使用範例
if __name__ == "__main__":
rpc = BitcoinRPC(
rpc_user=os.getenv("RPC_USER", "rpcuser"),
rpc_password=os.getenv("RPC_PASSWORD", "rpcpassword")
)
# 查詢節點狀態
print("比特幣節點狀態:")
print(f" 區塊高度: {rpc.get_blockchain_info()['blocks']}")
print(f" 連接節點: {rpc.get_network_info()['connections']}")
print(f" 錢包餘額: {rpc.get_balance()} BTC")
# 估算費用
fee_info = rpc.estimate_smart_fee(6)
print(f" 建議費用率: {fee_info['feerate']} BTC/kvB ({fee_info['feerate']*100000} sat/vB)")
# 列出未花費輸出
utxos = rpc.list_unspent(0)
print(f" UTXO 數量: {len(utxos)}")
監控腳本:自動化餘額監控與告警
以下腳本展示如何設置自動化監控系統。
#!/bin/bash
# monitor_balance.sh - 比特幣餘額監控腳本
# 配置
THRESHOLD_BALANCE=0.1 # 餘額告警閾值(BTC)
CHECK_INTERVAL=300 # 檢查間隔(秒)
RPC_USER="rpcuser"
RPC_PASSWORD="rpcpassword"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
check_balance() {
balance=$(bitcoin-cli -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASSWORD" getbalance 2>/dev/null)
if [ -z "$balance" ]; then
log "錯誤:無法連接到比特幣節點"
return 1
fi
log "當前餘額: $balance BTC"
# 餘額檢查
is_less=$(echo "$balance < $THRESHOLD_BALANCE" | bc -l)
if [ "$is_less" -eq 1 ]; then
log "警告:餘額低於閾值 $THRESHOLD_BALANCE BTC"
# 這裡可以添加發送告警郵件或 Telegram 訊息的代碼
# send_alert "比特幣餘額低於閾值: $balance BTC"
fi
}
check_mempool() {
mempool_info=$(bitcoin-cli -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASSWORD" getmempoolinfo)
size=$(echo "$mempool_info" | jq -r '.size')
mempool_min_fee=$(echo "$mempool_info" | jq -r '.mempoolminfee')
log "記憶池狀態: $size 筆交易, 最低費用: $mempool_min_fee BTC/kvB"
}
check_node_sync() {
blockchain_info=$(bitcoin-cli -rpcuser="$RPC_USER" -rpcpassword="$RPC_PASSWORD" getblockchaininfo)
blocks=$(echo "$blockchain_info" | jq -r '.blocks')
headers=$(echo "$blockchain_info" | jq -r '.headers')
ibd=$(echo "$blockchain_info" | jq -r '.initialblockdownload')
log "同步狀態: $blocks/$headers 區塊, IBD: $ibd"
if [ "$blocks" != "$headers" ]; then
log "警告:節點尚未完全同步"
fi
}
# 主循環
log "比特幣餘額監控服務啟動"
log "監控閾值: $THRESHOLD_BALANCE BTC"
while true; do
check_balance
check_mempool
check_node_sync
log "---"
sleep "$CHECK_INTERVAL"
done
常見錯誤處理
處理連線錯誤
# 測試連線
bitcoin-cli ping
# 檢查 RPC 是否響應
bitcoin-cli getblockchaininfo || echo "RPC 連線失敗"
# 檢查節點是否運行
pgrep -f bitcoind || echo "Bitcoin Core 未運行"
處理交易未確認
# 查詢交易狀態
bitcoin-cli getrawtransaction "txid" true
# 查詢節點記憶體
bitcoin-cli getmempoolentry "txid"
# 如果交易卡住,可以嘗試 RBF(Replace-By-Fee)
# 詳細參考:bitcoin-cli help bumpfee
處理費用估計失敗
# 如果 estimatesmartfee 返回錯誤
# 嘗試手動設定費用
# 查看網路實際費用
bitcoin-cli getrawmempool true | jq '[.[] | .fee / .vsize * 100000] | add / length'
# 設定固定費用
bitcoin-cli paytxfee 0.00002 # 2 sat/vB
安全性最佳實踐
限制 RPC 訪問
# 在 bitcoin.conf 中設定
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
rpcuser=strong_username
rpcpassword=very_strong_password
# 不要允許外部訪問
# rpcallowip=0.0.0.0/0 # 危險!
使用錢包加密
# 加密錢包(首次使用後)
bitcoin-cli encryptwallet "your_strong_password"
# 錢包解鎖(需要簽名交易時)
bitcoin-cli walletpassphrase "your_password" 300 # 解鎖 300 秒
# 鎖定錢包
bitcoin-cli walletlock
處理私鑰
# 導出私鑰(極度敏感!)
bitcoin-cli dumpprivkey "bc1q..."
# 導入私鑰
bitcoin-cli importprivkey "p2wpkh-p2sh:..."
# 備份錢包
bitcoin-cli backupwallet "/path/to/backup.dat"
指令速查表
| 類別 | 指令 | 功能 |
|---|---|---|
| 區塊鏈 | getblockchaininfo | 區塊鏈狀態總覽 |
| 區塊鏈 | getblockcount | 查詢區塊高度 |
| 區塊鏈 | getbestblockhash | 最新區塊雜湊 |
| 區塊鏈 | getmempoolinfo | 記憶池狀態 |
| 交易 | getrawtransaction | 查詢原始交易 |
| 交易 | decoderawtransaction | 解碼交易 |
| 交易 | sendrawtransaction | 廣播交易 |
| 費用 | estimatesmartfee | 智慧費用估算 |
| 費用 | paytxfee | 設定預設費用 |
| 錢包 | getwalletinfo | 錢包狀態 |
| 錢包 | getnewaddress | 生成新地址 |
| 錢包 | listunspent | 未花費輸出 |
| 錢包 | listtransactions | 交易歷史 |
| 網路 | getnetworkinfo | 網路節點資訊 |
| 網路 | getpeerinfo | 對等節點資訊 |
| 網路 | addnode | 節點管理 |
相關文章
相關文章
- Bitcoin Core RPC 快速上手 — 透過 JSON-RPC 介面與比特幣節點互動,常用指令教學。
- Bitcoin Core 節點運作 — 運行完整節點,理解比特幣網路的運作機制。
- 比特幣腳本語言入門 — 理解 Bitcoin Script 的基本指令與運作原理。
- UTXO 模型詳解 — 比特幣的未花費交易輸出模型與帳戶模型比較。
- CoinJoin 混幣詳解 — 比特幣隱私保護技術與實現方式。
延伸閱讀與來源
這篇文章對您有幫助嗎?
請告訴我們如何改進:
評論
發表評論
注意:由於這是靜態網站,您的評論將儲存在本地瀏覽器中,不會公開顯示。
目前尚無評論,成為第一個發表評論的人吧!