私链搭建(Docker)
下载镜像并运行
#下载
docker pull freewil/bitcoin-testnet-box
#运行容器
sudo docker run --name mybitcoin --user=root -t -i -p 19001:19001
-p 19011:19011 freewil/bitcoin-testnet-box
#查看日志
docker logs -f mybitcoin
开启两个节点
bitcoind -daemon -datadir=1
bitcoin-cli -datadir=1 getinfo
{
"version": 130200,
"protocolversion": 70015,
"walletversion": 130000,
"balance": 0.00000000,
"blocks": 0,
"timeoffset": 0,
"connections": 1,
"proxy": "",
"difficulty": 4.656542373906925e-10,
"testnet": false,
"keypoololdest": 1520921618,
"keypoolsize": 100,
"paytxfee": 0.00000000,
"relayfee": 0.00001000,
"errors": ""
}
bitcoind -daemon -datadir=2
bitcoin-cli -datadir=2 getinfo
{
"version": 130200,
"protocolversion": 70015,
"walletversion": 130000,
"balance": 0.00000000,
"blocks": 0,
"timeoffset": 0,
"connections": 1,
"proxy": "",
"difficulty": 4.656542373906925e-10,
"testnet": false,
"keypoololdest": 1520921618,
"keypoolsize": 100,
"paytxfee": 0.00000000,
"relayfee": 0.00001000,
"errors": ""
}
#根据balance可以看到,两方的比特币都是0
模拟挖矿
#产生200个区块
bitcoin-cli -datadir=1 generate 200
[
"0df24dddfb187b55a08f0e4470e3b51a5994699da7456a4061050c29cf99670f",
"788ea259946064cef2d5d2fa48fd3285868f4e64bd96daa2dc0b9207a22be3b3",
"054e4e77e8e05cba985e5006bf4fe75b22759716dd586a1f541b892a278f49fa",
...
]
#查看信息
bitcoin-cli -datadir=1 getinfo
{
"version": 130200,
"protocolversion": 70015,
"walletversion": 130000,
"balance": 5000.00000000,
"blocks": 200,
"timeoffset": 0,
"connections": 1,
"proxy": "",
"difficulty": 4.656542373906925e-10,
"testnet": false,
"keypoololdest": 1520921618,
"keypoolsize": 100,
"paytxfee": 0.00000000,
"relayfee": 0.00001000,
"errors": ""
}
#查看账户余额
bitcoin-cli --datadir=1 listaccounts
{
"": 5000.00000000
}
#查看账户地址
bitcoin-cli --datadir=1 getaddressesbyaccount ""
[
"mwfkSxRsPjAvxWhTh8dzKtWy7z8UiKMwzd"
]
#查看账户余额
bitcoin-cli --datadir=2 listaccounts
{
"": 0.00000000
}
#查看账户地址
bitcoin-cli --datadir=2 getaddressesbyaccount ""
[
"muwmDp87VSSoE7Sy4WryYtgQ8ZUbh7Lret"
]
转账10个比特币
#转账10个比特币
bitcoin-cli -datadir=1 sendtoaddress "muwmDp87VSSoE7Sy4WryYtgQ8ZUbh7Lret"" 10
#生成10个区块
bitcoin-cli -datadir=1 generate 10
查看转账结果
bitcoin-cli -datadir=2 getinfo
{
"version": 130200,
"protocolversion": 70015,
"walletversion": 130000,
"balance": 10.00000000,
"blocks": 210,
"timeoffset": 0,
"connections": 1,
"proxy": "",
"difficulty": 4.656542373906925e-10,
"testnet": false,
"keypoololdest": 1520921618,
"keypoolsize": 100,
"paytxfee": 0.00000000,
"relayfee": 0.00001000,
"errors": ""
}
利用curl进行操作
#用curl发起getinfo请求
curl --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getinfo","params":[]}' -H 'content-type:text/plain;' http://admin1:123@127.0.0.1:19000/
#查看结果
{
"result":{
"version":130200,
"protocolversion":70015,
"walletversion":130000,
"balance":5979.99991660,
"blocks":220,"timeoffset":0,
"connections":1,
"proxy":"",
"difficulty":4.656542373906925e-10,
"testnet":false,
"keypoololdest":1520926587,
"keypoolsize":100,
"paytxfee":0.00000000,
"relayfee":0.00001000,
"errors":""
},
"error":null,
"id":"curltext"
}
最后更新于