(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
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
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
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 -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/
make start
make getinfo
make cli command=getbalance //command=后面可以输入命令
make stop
状态相关
make cli command=getblockchaininfo
make cli command=getwalletinfo
make cli command=getnetworkinfo
make getinfo
区块相关
make cli command="generate 10"
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'"
make cli command="getreceivedbyaccount 'user' 1"
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
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]"
make cli command="sendtoaddress [ADDRESS] [AMOUNT]"
make cli command="sendtoaddress 2NEVRE7j9ZzLmFZREnf3d9QvTq9Y8hP9UqM 1000"
make cli command="sendtoaddress 2N1XpzLA1ZtUpy5WRfiRJRnhgTJXFmejPCs 1000"
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"
钱包相关
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该命令貌似已被弃用)
make cli command="setgenerate true 1"
make cli command="setgenerate false"
关闭bitcoin
make -C /data/blockchain/btc/fast stop
往期精彩回顾:
-
区块链知识系列
-
密码学系列
-
零知识证明系列
-
共识系列
-
公链调研系列
-
比特币系列
-
以太坊系列
-
EOS系列
-
Filecoin系列
-
联盟链系列
-
Fabric系列
-
智能合约系列
-
Token系列
|