2018-2-4 号更新
这篇文章总结在开发比特币应用业务开发时本地测试模式的设置我们不需要 GUI 页面,在 Ubuntu 安装 bitcoin core daemon without GUI (bitcoind) 即可
在这里有一点需要注意,由于我们不需要图形界面 ./configure 时加上 --without-gui 参数。编译根据官方文档安装 bitcoin/doc/build-unix.md ,
然后就是 bitcoind 配置
mkdir ~/.bitcoinwget https://github.com/bitcoin/bitcoin/raw/master/contrib/debian/examples/bitcoin.confchmod 600 ~/.bitcoin/bitcoin.conf
修改下列参数配置:
regtest=1rpcuser=rpcusernamerpcpassword=rpcpassword# By default, only RPC connections from localhost are allowed. Specify# as many rpcallowip= settings as you like to allow connections from# other hosts (and you may use * as a wildcard character):rpcallowip=192.168.100.2walletnotify=/home/username/script/bitcoind_notify.rb %srpcport=18332minconf=2
注意 rpcallowip 这个选项,这里的 rpcallowip 填的是允许 rpc 链接的主机ip。接着就是启动测试链
bitcoind -conf=/home/username/bitcoind_pri/bitcoin_pri.conf -daemon -datadir=/home/username/bitcoind_pri -txindex=1 -deprecatedrpc=signrawtransaction
此时运行 bitcoin-cli -regtest -getinfo
即可看到运行在服务器上的私有链节点信息。我这里通过 bitcoin-cli -regtest generate [num]
生成了区块。
{"version": 169900,"protocolversion": 70015,"walletversion": 159900,"balance": 0.00000000,"blocks": 183871,"timeoffset": -1,"connections": 7,"proxy": "","difficulty": 1583177.847444009,"testnet": false,"keypoololdest": 1517675490,"keypoolsize": 1000,"paytxfee": 0.00000000,"relayfee": 0.00001000,"warnings": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"}
接下来就是一下常用的 bitcoin-cli 命令在私有链上的使用例子:
当交易被广播后,矿工把这笔交易添加到区块中,达到了钱包的 minconf 数量就表示交易成功。那么在私有链上,可以通过 bitcoin-cli -regtest generate 1
命令生成一个区块,确认当前钱包中发生的交易。
联系客服