(1)連接到公鏈
前臺運行
bitcoind
#如果報錯,應該是環境變數的關系
bitcoind: error while loading shared libraries: libboost_system.so.1.64.0: cannot open shared object file: No such file or directory
#配置環境變數
vim ~/.bashrc
#添加以下內容:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/local/lib:/usr/local/lib64
export LD_LIBRARY_PATH
export PYTHONPATH=.
#保存退出后執行
source ~/.bashrc
后臺運行
啟動并同步區塊
bitcoind -daemon
啟動 不同步區塊
bitcoind -daemon -maxconnections=0
##### 公鏈跑這句 ############
bitcoind -daemon -deprecatedrpc=estimatefee
#能使用挖礦命令 (已被棄用)
bitcoind -daemon -deprecatedrpc=setgenerate
#啟用賬戶的命令
bitcoind -daemon -deprecatedrpc=accounts
#不同步區塊
bitcoind -daemon -maxconnections=0 -deprecatedrpc=accounts
常用的命令列命令
#增加同步節點
bitcoin-cli addnode "119.23.63.114:8333" onetry
#查看同步資訊
bitcoin-cli -getinfo
#查看account與余額
bitcoin-cli listaccounts
#查看交易資訊
bitcoin-cli listtransactions
#列出整個錢包的所有地址
bitcoin-cli getaddressesbyaccount ""
#列出整個錢包的所有地址和余額
bitcoin-cli listaddressgroupings
#顯示錢包當前管理的所有地址的余額總和
bitcoin-cli getbalance
bitcoin-cli getbalance 地址
#停止運行
bitcoin-cli stop
(2)連接到測驗網路
前臺運行
bitcoind -testnet
bitcoind -testnet -gen //-gen引數代表開始挖礦
##### 測驗鏈跑這句 ############
開始運行 (后臺運行)
bitcoind -testnet -daemon -deprecatedrpc=accounts
不同步區塊
bitcoind -testnet -daemon -maxconnections=0 -deprecatedrpc=accounts
#############################
#停止運行
bitcoin-cli -testnet stop
#生成區塊
bitcoin-cli -regtest generate 101
#生成錢包地址
bitcoin-cli -regtest getnewaddress
#生成錢包地址 指定賬戶
bitcoin-cli -regtest getnewaddress "platform"
#查詢地址的私鑰
bitcoin-cli -regtest dumpprivkey 2MvSvdJBGSZVfdMGYXFpnDofv3ADQBeXPq4
#轉賬 (單位是btc)
bitcoin-cli -regtest sendtoaddress [ADDRESS] [AMOUNT]
bitcoin-cli -regtest sendtoaddress 2MxNL6tPRKNCEWqrC1z5Sw9WWNVqA39nDc8 2
#查看交易資訊(受錢包管理的地址的交易)
bitcoin-cli -regtest listtransactions
bitcoin-cli -regtest gettransaction txid
bitcoin-cli decoderawtransaction hex
常用錢包命令
#**生成錢包地址**
bitcoin-cli -testnet getnewaddress
#**加密錢包**
bitcoin-cli -testnet encryptwallet "123456"
#**解鎖錢包** 最后一個引數是解鎖時間
bitcoin-cli -testnet walletpassphrase "123456" 600
#**查詢地址的私鑰**
bitcoin-cli -testnet dumpprivkey 2MvSvdJBGSZVfdMGYXFpnDofv3ADQBeXPq4
#**匯入相應地址到錢包**
bitcoin-cli -testnet importaddress mfcwZvnSE44MuHoNPZcrwvaGSsGnTerKa2
#**匯入相應地址的私鑰到錢包**
bitcoin-cli -testnet importprivkey cVYGW6TbAVDpP183yPJkGPwAYgoNugnq6ueywcNAY2uRGdyi4X38
#匯出錢包
bitcoin-cli -testnet backupwallet mywallet
#匯入錢包
bitcoin-cli -testnet importwallet mywallet
(3)私鏈
后臺運行
bitcoind -regtest -daemon -deprecatedrpc=accounts -datadir=/root/blockchain/btc
bitcoind -regtest -daemon -deprecatedrpc=accounts -datadir=/root/blockchain/btc -rpcuser=admin1 -rpcpassword=123 -rpcallowip=0.0.0.0/0
#設定了rpc埠 賬號 密碼的話,使用bitcoin-cli時也得相應設定 -rpcport=19001
bitcoin-cli -regtest -rpcuser=admin1 -rpcpassword=123 -getinfo
bitcoin-cli -regtest -rpcuser=admin1 -rpcpassword=123 -datadir=/root/blockchain/btc getnewaddress "platform"
bitcoin-cli -regtest -rpcuser=admin1 -rpcpassword=123 stop
#如果指定了路徑的話,使用bitcoin-cli時可以不指定rcp密碼等
bitcoin-cli -datadir=/root/blockchain/btc -getinfo
bitcoin-cli -datadir=/root/blockchain/btc getnewaddress "platform"
bitcoin-cli -datadir=/root/blockchain/btc stop
#停止運行
bitcoin-cli -regtest stop
(4)通過 curl 直接調 rpc介面 (RESTAPI)
curl --user admin1 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getaddressesbyaccount", "params": ["tabby"] }' -H 'content-type: text/plain;' http://192.168.131.135:18444/
(5)使用make命令
cd blockchain/btc/regtest/
#在目錄下放個Makefile檔案,里面配置好對make命令的回應, 然后就可以
make start
make getinfo
make cli command=getbalance //command=后面可以輸入命令
make stop
#注意帳戶余額變動,與網路上的實際硬幣無關
#當您使用sendfrom匯款時,指定的賬戶被扣除,但創建的實際鏈上交易始終使用錢包控制的任意個硬幣,再次說明:鏈上硬幣(交易產出)和賬戶余額之間沒有關系
狀態相關
#網路概覽(包括網路型別 區塊高度)
make cli command=getblockchaininfo
#錢包狀態
make cli command=getwalletinfo
#查看當前節點的網路狀況
make cli command=getnetworkinfo
#基本資訊
make getinfo
區塊相關
#生成區塊
make cli command="generate 10"
#查區塊號對應的hash
make cli command="getblockhash 0"
#查區塊資訊
make cli command="getblock [blockhash]"
#查區塊詳細資訊
make cli command="getblock [blockhash] 2"
賬戶地址
#生成錢包地址 默認賬戶
make cli command=getnewaddress
#生成錢包地址 指定賬戶
make cli command="getnewaddress platform"
#列出默認賬戶下的所有地址
make cli command="getaddressesbyaccount ''"
#列出指定賬戶下的所有地址
make cli command="getaddressesbyaccount platform"
make cli command="getaddressesbyaccount user"
#***查詢一個地址的相關資訊,可用于驗證一個地址是否有效 ***
make cli command="validateaddress 2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg"
make cli command="validateaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM"
#回傳指定地址相關聯的帳戶
make cli command="getaccount 2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg"
#將地址關聯到指定帳戶
make cli command="setaccount 2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg user"
#回傳指定賬戶當前的幣收款地址
make cli command="getaccountaddress 'platform'"
#回傳指定賬戶上收到至少[minconf]個確認的收款交易總金額(不包括付款)
make cli command="getreceivedbyaccount 'user' 1"
#回傳指定地址上收到至少[minconf]個確認的收款交易總金額
make cli command="getreceivedbyaddress '2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg' 1"
賬戶余額
#錢包的總余額
make cli command="getbalance"
#錢包內指定賬戶的總余額
make cli command="getbalance platform"
make cli command="getbalance user"
#回傳錢包上的所有地址資訊(地址,余額,所屬賬戶)
make cli command=listaddressgroupings
#列出賬戶的收款資訊
make cli command=listreceivedbyaccount
#**列出地址的收款資訊**
make cli command=listreceivedbyaddress
#**列出賬戶與余額**
make cli command=listaccounts
#列出全部未花費的交易輸出
make cli command=listunspent
#列出至少 X 個確認的未花費交易輸出,并指定地址過濾器,
make cli command="listunspent 0 9999999 '[\"2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg\"]'"
交易相關
#查看交易資訊(受錢包管理的地址的交易)
make cli command=listtransactions
#查看單筆交易資訊
make cli command="gettransaction [txid]"
make cli command="gettransaction 8d44aa1523d1b44519fbfff3f4f0b9373877ad4151d4588673b35518e90a0547"
#查看單筆原始資料
make cli command="getrawtransaction [txid]"
#解碼交易的原始資料
make cli command="decoderawtransaction [hex]"
#轉賬 (單位是btc)
make cli command="sendtoaddress [ADDRESS] [AMOUNT]"
make cli command="sendtoaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM 1000"
make cli command="sendtoaddress 2N1XpzLA1ZtUpy5WRfiRJRnhgTJXFmejPCs 1000"
#從指定賬戶<fromaccount>向指定地址<tobitcoinaddress> 發送指定金額<amount>的BTC,確保帳戶擁有得到[minconf]個確認的有效余額
make cli command="sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to] "
make cli command="sendfrom platform 2NAvfLb7p4BmLAUKiVGTyfCFAAFJ2h88CNg 5"
#估算交易手續費
make cli command="estimatesmartfee 6"
#錢包內賬戶間轉賬
make cli command="move <fromaccount> <toaccount> <amount> [minconf=1] [comment]"
make cli command="move user platform 10"
#move 轉賬 ★★★★ 賬戶 <fromaccount> <toaccount> <amount> [minconf=1] [comment] 把你錢包中一個賬戶<fromaccount>上的指定金額<amount> 轉移到另一個賬戶<toaccount>上, Move from one account in your wallet to another N
錢包相關
make cli command="encryptwallet 123456"
#**解鎖錢包** 最后一個引數是解鎖時間
make cli command="walletpassphrase 123456 600000"
#**鎖定錢包**
make cli command="walletlock"
#**修改錢包密碼 原 新**
make cli command="walletpassphrasechange 123456 123123"
#**重新填滿密鑰池**
make cli command="keypoolrefill"
#**查詢地址的私鑰**
make cli command="dumpprivkey 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM"
#**匯入地址到錢包默認賬戶**
make cli command="importaddress mfcwZvnSE44MuHoNPZcrwvaGSsGnTerKa2"
#**匯入地址到錢包指定賬戶** 不重新掃描塊 適用于新生成的地址
make cli command="importaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM platform false"
#**匯入地址到錢包指定賬戶** 重新掃描塊 適用于有余額的地址
make cli command="importaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM platform true"
#******匯入無余額的私鑰到錢包*******
make cli command="importprivkey cSKLMu6HVX9TyJPgqJSCu4SWe7aLcpdmYgo76cgQgAV4NwfkgFJq '' false"
#******匯入有余額的私鑰到錢包*******
make cli command="importprivkey cSKLMu6HVX9TyJPgqJSCu4SWe7aLcpdmYgo76cgQgAV4NwfkgFJq platform true"
#匯出錢包
make cli command="backupwallet mywallet"
#匯入錢包
make cli command="importwallet mywallet"
mining開關(setgenerate該命令貌似已被棄用)
#setgenerate 設定是否采礦 ★★★★ 采礦 <generate> [genproclimit] 根據<generate>引數的值(true/false)決定客戶端是否采礦,[genproclimit]引數指定采礦最大執行緒數,-1代表無限制, <generate> is true or false to turn generation on or off.Generation is limited to [genproclimit] processors, -1 is unlimited. N
#開
make cli command="setgenerate true 1"
#關
make cli command="setgenerate false"
關閉bitcoin
make -C /data/blockchain/btc/fast stop
-
往期精彩回顧:
- 區塊鏈知識系列
- 密碼學系列
- 零知識證明系列
- 共識系列
- 公鏈調研系列
- 位元幣系列
- 以太坊系列
- EOS系列
- Filecoin系列
- 聯盟鏈系列
- Fabric系列
- 智能合約系列
- Token系列
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/305762.html
標籤:區塊鏈
上一篇:Fabric_sdk_go:QueryBlockConfig failed: QueryBlockConfig failed: target(s) required
下一篇:量化交易機器人
