Feb 28

自建 BTC RegTest 测试网络 不指定

felix021 @ 2018-2-28 18:35 [IT » Blockchain] 评论(0) , 引用(0) , 阅读(13003) | Via 本站原创 | |
# 1. 编译安装 (@ubuntu)
引用
sudo mkdir -p /usr/local/services/bitcoin
sudo apt-get install autoconf pkg-config libtool build-essential libdb++-dev libboost-dev libssl-dev libevent-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev libboost-test-dev libboost-*-dev

git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git checkout v0.15.1

./autogen.sh
./configure --prefix=/usr/local/services/bitcoin --with-incompatible-bdb
make -j 6 &> make.log &
sudo make install

echo 'export PATH=$PATH:/usr/local/services/bitcoin/bin' >> ~/.bashrc


# 2. 启动 regtest 网络

$ bitcoind -regtest -txindex -daemon

说明:

-regtest 表示启动的是 regtest 网络;不同网络之间的区别在于创世区块不同。

-txindex 表示对所有的交易进行索引;否则默认只对与钱包地址有关的交易索引

-daemon 表示在后台运行

也可以通过写入配置文件 ~/.bitcoin/bitcoin.conf 的方式 :
引用
regtest=1

rpcbind=127.0.0.1
rpcallowip=127.0.0.1
rpcuser=test
rpcpassword=test

server=1
daemon=1
txindex=1

然后直接调用 bitcoind 就好了。

# 3. 基本命令

引用
$ bitcoin-cli -regtest generate 101 #挖101个block;挖矿的奖励要在100个block以后才能使用
[
  "26d4fb4dd449b93ebbda9a36f390d2c7b1dd9557e662840fe61b1f6e3a09d218",
  .... #共101块
]

$ bitcoin-cli -regtest getaccountaddress "" #钱包默认账户的地址; 测试网络的地址是m或n开头的
mmmSrYNiRQzeiTypt8rF9L3F742PW4ksmL

$ bitcoin-cli -regtest getbalance #查看挖矿奖励(默认账户)
50.00000000

$ bitcoin-cli -regtest getnewaddress #分配一个新的地址
mn41xHRzXuUAAVtujPLLo3Hzbe63GSP117

$ bitcoin-cli -regtest sendtoaddress mn41xHRzXuUAAVtujPLLo3Hzbe63GSP117 10 #往这个新生成的地址转10个BTC;输出是交易的hash
4deb2fbb98d9029a4e5808b8236d1119ad7315efdfe7406a88c923f5d4b0d5af

$ bitcoin-cli -regtest getrawtransaction 4deb2fbb98d9029a4e5808b8236d1119ad7315efdfe7406a88c923f5d4b0d5af true #查看交易详细信息
(输出json,包含size、vin、vout等,因为还没被打包进区块链,所以没有confirmations)

$ bitcoin-cli -regtest generate 1
[
    "4deb2fbb98d9029a4e5808b8236d1119ad7315efdfe7406a88c923f5d4b0d5af"
]

$ bitcoin-cli -regtest getrawtransaction 4deb2fbb98d9029a4e5808b8236d1119ad7315efdfe7406a88c923f5d4b0d5af true #查看交易详细信息
(输出json,这次可以看到 blockhash 和 confirmations 了,说明交易已经被打包)

$ bitcoin-cli -regtest listreceivedbyaddress #查看收到的BTC
[
  {
    "address": "mn41xHRzXuUAAVtujPLLo3Hzbe63GSP117",
    "account": "",
    "amount": 10.00000000,
    "confirmations": 1,
    "label": "",
    "txids": [
      "4deb2fbb98d9029a4e5808b8236d1119ad7315efdfe7406a88c923f5d4b0d5af"
    ]
  }
]




欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]