比特币Bitcoin Core
可执行程序
1、bitcoin-cli: RPC客户端。
2、bitcoin-tx: bitcoin-tx工具。
3、test_bitcoin: 单元测试。
4、bitcoind: 服务端。
5、bitcoin-qt: 带用户界面的客户端。
6、bitcoin-wallet: 离线钱包。
启动程序
1、启动bitcoin-qt。
bitcoin-qt -prune=550
bitcoin-qt -testnet -prune=550
bitcoin-qt -regtest -prune=550
2. 启动bitcoind。
bitcoind -prune=550
bitcoind -testnet -prune=550
bitcoind -regtest -prune=550
**3. 启动bitcoin-cli。**
bitcoin-cli
bitcoin-cli -testnet
bitcoin-cli -regtest
默认: 主网络,-testnet: 测试网络,-regtest: 回归模式。
bitcoind端口
1、主网络:8332
2、测试网络:18332
3、回归测试:18443
4、signet: 38332
bitcoin配置文件
~~/.bitcoin/bitcoin.conf
bitcoin-cli用法
1、查看帮助:bitcoin-cli help
2、创建钱包:bitcoin-cli createwallet liteng
3、查询余额:bitcoin-cli getbalance
4、获取新的收款地址:bitcoin-cli getnewaddress "标签" "地址类型"
标签默认为空字符串;地址类型:legacy, p2sh-segwit, bech32
5、产生101个区块:bitcoin-cli -regtest generatetoaddress 101 $ADDRESS
由于经过100次确认才能消费,所以101个区块只有最初的第1个区块产生的50个比特币能消费。
6、发送比特币:bitcoin-cli sendtoaddress $ADDRESS1 10.00 $ADDRESS2
从ADDRESS1向ADDRESS2发送10个比特币。
7、列出确认的未花费的交易:bitcoin-cli listunspent
8、列出所有未花费的交易:bitcoin-cli -listunspent 0
9、创建原生交易:bitcoin-cli createrawtransaction '[{"txid": "交易ID", "vout": "输出索引"}]' '{"地址": 金额}'
10、解码原生交易:bitcoin-cli decoderawtransaction $RAW_TX
11、使用钱包密钥签名原生交易:bitcoin-cli -regtest signrawtransactionwithwallet $RAW_TX
12、发送交易到节点并广播:bitcoin-cli -regtest sendrawtransaction $SIGNED_RAW_TX
13、导出私钥:bitcoin-cli dumpprivkey $UTXO1_ADDRESS
14、使用密钥签名原生交易:bitcoin-cli signrawtransactionwithkey $RAW_TX '["'$UTXO1_PRIVATE_KEY'"]'
'[{"txid": "'$UTXO1_TXID'", "vout": '$UTXO1_VOUT', "scriptPubKey": "'$PubKey'"}]'
15、获取原生交易缓存池:bitcoin-cli getrawmempool
16、加载钱包:bitcoin-cli loadwallet $WALLET_NAME
17、CURL获取余额:curl ~-~-user liteng ~-~-data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getbalance", "params": ["*", 6]}' -H 'content-type: text/plain;' http:~/~/127.0.0.1:18443/
创建自定义signet
1、使用regtest创建signetchallenge。
bitcoind -regtest ~-~-prune=550
ADDR=$(bitcoin-cli -regtest getnewaddress '' bech32) # 获取地址
PRIVKEY=$(bitcoin-cli -regtest dumpprivkey $ADDR) # 获取密钥
PUBKEY=$(bitcoin-cli -regtest getaddressinfo $ADDR | jq -r .pubkey) # 获取公钥
LENX2=$(printf $PUBKEY | wc -c)
LEN=$((LENX2/2))
LENHEX=$(echo "obase=16; $LEN" | bc)
SCRIPT=$(echo 51${LENHEX}${PUBKEY}51ae) # signetchallenge
ADDR: bcrt1qy6t53qcvu2p62673alh6g9vaaeyy8da4yzmkwv
PRIVKEY: cPzQ6GwbRRjbcc6Ed8XRYWy4mij7YbJK6GrJJCcr9TeFhqPE5NdT
PUBKEY: 03bb1425519423e645b7c687747d5bf6a983719b3ab6bdd39eb214f1bcca47d667
SCRIPT: 512103bb1425519423e645b7c687747d5bf6a983719b3ab6bdd39eb214f1bcca47d66751ae
2、创建signet。
bitcoind -signet -signetchallenge=512103bb1425519423e645b7c687747d5bf6a983719b3ab6bdd39eb214f1bcca47d66751ae
挖矿
1、cpuminer独立挖矿:./minerd -o http:~/~/localhost:8332 -a sha256d -O liteng:x ~-~-coinbase-addr=bc1qp998sjl4dph9mt7rxvkfsfkw4pnvqzaqc8lr4m
2、bfgminer独立挖矿:./bfgminer -o http:~/~/localhost:8332 -O liteng:x ~-~-generate-to 15xNUqbrw4wLkBPcgh1rGiANguueTdPRgu
3、获取区块模板。
getblocktemplate '{"rules":["segwit"]}'
4、获取挖矿信息。
getmininginfo
5、获取当前哈希值。
getnetworkhashps
6、优先交易。
prioritisetransaction
7、提交区块。
submitblock
8、提交头。
submitheader
常见问题
显示:unknown syncing headers
参考:https:~/~/ask.csdn.net/questions/2705118
bitcoin-qt -reindex
bitcoin-qt控制台帮助
Blockchain
getbestblockhash
getblock "blockhash" ( verbosity )
getblockchaininfo
getblockcount
getblockfilter "blockhash" ( "filtertype" )
getblockhash height
getblockheader "blockhash" ( verbose )
getblockstats hash_or_height ( stats )
getchaintips
getchaintxstats ( nblocks "blockhash" )
getdifficulty
getmempoolancestors "txid" ( verbose )
getmempooldescendants "txid" ( verbose )
getmempoolentry "txid"
getmempoolinfo
getrawmempool ( verbose mempool_sequence )
gettxout "txid" n ( include_mempool )
gettxoutproof ["txid",...] ( "blockhash" )
gettxoutsetinfo ( "hash_type" )
preciousblock "blockhash"
pruneblockchain height
savemempool
scantxoutset "action" ( [scanobjects,...] )
verifychain ( checklevel nblocks )
verifytxoutproof "proof"
Control
getmemoryinfo ( "mode" )
getrpcinfo
help ( "command" )
logging ( ["include_category",...] ["exclude_category",...] )
stop
uptime
Generating
generateblock "output" ["rawtx/txid",...]
generatetoaddress nblocks "address" ( maxtries )
generatetodescriptor num_blocks "descriptor" ( maxtries )
~
Mining
getblocktemplate ( "template_request" )
getmininginfo
getnetworkhashps ( nblocks height )
prioritisetransaction "txid" ( dummy ) fee_delta
submitblock "hexdata" ( "dummy" )
submitheader "hexdata"
~
Network
addnode "node" "command"
clearbanned
disconnectnode ( "address" nodeid )
getaddednodeinfo ( "node" )
getconnectioncount
getnettotals
getnetworkinfo
getnodeaddresses ( count )
getpeerinfo
listbanned
ping
setban "subnet" "command" ( bantime absolute )
setnetworkactive state
Rawtransactions
analyzepsbt "psbt"
combinepsbt ["psbt",...]
combinerawtransaction ["hexstring",...]
converttopsbt "hexstring" ( permitsigdata iswitness )
createpsbt [{"txid":"hex","vout":n,"sequence":n},...] [{"address":amount},{"data":"hex"},...] ( locktime replaceable )
createrawtransaction [{"txid":"hex","vout":n,"sequence":n},...] [{"address":amount},{"data":"hex"},...] ( locktime replaceable )
decodepsbt "psbt"
decoderawtransaction "hexstring" ( iswitness )
decodescript "hexstring"
finalizepsbt "psbt" ( extract )
fundrawtransaction "hexstring" ( options iswitness )
getrawtransaction "txid" ( verbose "blockhash" )
joinpsbts ["psbt",...]
sendrawtransaction "hexstring" ( maxfeerate )
signrawtransactionwithkey "hexstring" ["privatekey",...] ( [{"txid":"hex","vout":n,"scriptPubKey":"hex","redeemScript":"hex","witnessScript":"hex","amount":amount},...] "sighashtype" )
testmempoolaccept ["rawtx",...] ( maxfeerate )
utxoupdatepsbt "psbt" ( ["",{"desc":"str","range":n or [n,n]},...] )
Util
createmultisig nrequired ["key",...] ( "address_type" )
deriveaddresses "descriptor" ( range )
estimatesmartfee conf_target ( "estimate_mode" )
getdescriptorinfo "descriptor"
getindexinfo ( "index_name" )
signmessagewithprivkey "privkey" "message"
validateaddress "address"
verifymessage "address" "signature" "message"
Wallet
abandontransaction "txid"
abortrescan
addmultisigaddress nrequired ["key",...] ( "label" "address_type" )
backupwallet "destination"
bumpfee "txid" ( options )
createwallet "wallet_name" ( disable_private_keys blank "passphrase" avoid_reuse descriptors load_on_startup )
dumpprivkey "address"
dumpwallet "filename"
encryptwallet "passphrase"
getaddressesbylabel "label"
getaddressinfo "address"
getbalance ( "dummy" minconf include_watchonly avoid_reuse )
getbalances
getnewaddress ( "label" "address_type" )
getrawchangeaddress ( "address_type" )
getreceivedbyaddress "address" ( minconf )
getreceivedbylabel "label" ( minconf )
gettransaction "txid" ( include_watchonly verbose )
getunconfirmedbalance
getwalletinfo
importaddress "address" ( "label" rescan p2sh )
importdescriptors "requests"
importmulti "requests" ( "options" )
importprivkey "privkey" ( "label" rescan )
importprunedfunds "rawtransaction" "txoutproof"
importpubkey "pubkey" ( "label" rescan )
importwallet "filename"
keypoolrefill ( newsize )
listaddressgroupings
listlabels ( "purpose" )
listlockunspent
listreceivedbyaddress ( minconf include_empty include_watchonly "address_filter" )
listreceivedbylabel ( minconf include_empty include_watchonly )
listsinceblock ( "blockhash" target_confirmations include_watchonly include_removed )
listtransactions ( "label" count skip include_watchonly )
listunspent ( minconf maxconf ["address",...] include_unsafe query_options )
listwalletdir
listwallets
loadwallet "filename" ( load_on_startup )
lockunspent unlock ( [{"txid":"hex","vout":n},...] )
psbtbumpfee "txid" ( options )
removeprunedfunds "txid"
rescanblockchain ( start_height stop_height )
send [{"address":amount},{"data":"hex"},...] ( conf_target "estimate_mode" fee_rate options )
sendmany "" {"address":amount} ( minconf "comment" ["address",...] replaceable conf_target "estimate_mode" fee_rate verbose )
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount replaceable conf_target "estimate_mode" avoid_reuse fee_rate verbose )
sethdseed ( newkeypool "seed" )
setlabel "address" "label"
settxfee amount
setwalletflag "flag" ( value )
signmessage "address" "message"
signrawtransactionwithwallet "hexstring" ( [{"txid":"hex","vout":n,"scriptPubKey":"hex","redeemScript":"hex","witnessScript":"hex","amount":amount},...] "sighashtype" )
unloadwallet ( "wallet_name" load_on_startup )
upgradewallet ( version )
walletcreatefundedpsbt ( [{"txid":"hex","vout":n,"sequence":n},...] ) [{"address":amount},{"data":"hex"},...] ( locktime options bip32derivs )
walletlock
walletpassphrase "passphrase" timeout
walletpassphrasechange "oldpassphrase" "newpassphrase"
walletprocesspsbt "psbt" ( sign "sighashtype" bip32derivs )
Zmq
getzmqnotifications