基于Docker搭建比特币测试网络

搭建比特币测试网络

下载比特币测试网络镜像

1
~ docker pull freewill/bitcoin-testnet-box

运行docker images查看:

1
2
REPOSITORY TAG IMAGE ID CREATED SIZE
freewil/bitcoin-testnet-box latest 4dac47b76f09 4 months ago 262MB

运行Docker镜像

1
docker run -t -i -p 19001:19001 -p 19011:19011 freewil/bitcoin-testnet-box

上述命令中的19001 和 19011是配置给两个节点提供RPC服务的端口。

启动比特币测试网络

运行make start命令启动。

1
2
3
4
5
tester@84fdf4019179 ~/bitcoin-testnet-box$ make start
bitcoind -datadir=1 -daemon
Bitcoin server starting
bitcoind -datadir=2 -daemon
Bitcoin server starting

查看节点信息

使用make getinfo命令获得节点信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
tester@84fdf4019179 ~/bitcoin-testnet-box$ make getinfo
bitcoin-cli -datadir=1 -getinfo
{
"version": 160200,
"protocolversion": 70015,
"walletversion": 159900,
"balance": 0.00000000,
"blocks": 0,
"timeoffset": 0,
"connections": 1,
"proxy": "",
"difficulty": 4.656542373906925e-10,
"testnet": false,
"keypoololdest": 1544519547,
"keypoolsize": 1000,
"paytxfee": 0.00000000,
"relayfee": 0.00001000,
"warnings": ""
}
bitcoin-cli -datadir=2 -getinfo
{
"version": 160200,
"protocolversion": 70015,
"walletversion": 159900,
"balance": 0.00000000,
"blocks": 0,
"timeoffset": 0,
"connections": 1,
"proxy": "",
"difficulty": 4.656542373906925e-10,
"testnet": false,
"keypoololdest": 1544519547,
"keypoolsize": 1000,
"paytxfee": 0.00000000,
"relayfee": 0.00001000,
"warnings": ""
}

初始化和测试区块链数据

产生区块

使用make generate命令产生一个区块。

1
2
3
4
5
tester@84fdf4019179 ~/bitcoin-testnet-box$ make generate
bitcoin-cli -datadir=1 generate 1
[
"793a86b807ac6595529bfcbd58118fe09706aa64e736fd9448f63cb7d38a9eb1"
]

使用make generate BLOCKS=数量命令批量产生区块。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
tester@84fdf4019179 ~/bitcoin-testnet-box$ make generate BLOCKS=10
bitcoin-cli -datadir=1 generate 10
[
"3a9d94273198bee2c448fcdeb2925a8e2685adc8f239f77fc64ce8b6f637b9aa",
"3bd20765fa0162e1a17b2051c5b5711bfb271b25c88238f42a4351301d9e5ce6",
"308e612999026677733ffd2954833e58d456e663e982037880f455ee5932c59c",
"0b62ecc7990ac6770848655f10d4277d89df4ef1092fb7e25c0b2aa87a2bcbec",
"5de9fbe62f7dc499568b41300610e3aa8b489a61375b3fa26717f65eab85392a",
"14a000cae88c1bd881c06ba24a7a31364ff369578912e5a5abcf4023a0a28557",
"414b9361debb64366cdf61b1acf5211e17b5f4f978ae5bfcad1aac916503e8a9",
"75d1176835a12cf09cd51663fd7bd40e8e4fef15b392bf7e6ff94188398da041",
"3d71ee9885fc9586013ce1c2954e197d726b25981c6977195e184fa90cdfa71d",
"149dfcdc4cdfcbeeaf432bab90deca9a7b2b3935d359366ce652b071d6b72bb4"
]

参考

https://blog.csdn.net/yzpbright/article/details/81004202

https://www.codeooze.com/blockchain/bitcoind-running-in-docker/