私链搭建(Linux)
程序下载
https://bitcoin.org/en/download
配置环境
#解压
tar -zxf bitcoin-0.16.0-x86_64-linux-gnu.tar.gz
#创建连个文件夹1和2
cd bitcoin-0.16.0/bin
mkdir 1
mkdir 2
#下载默认配置文https://github.com/bitcoin/bitcoin/blob/master/contrib/debian/examples/bitcoin.conf
#分别修改对应内容,然后放到1、2文件夹下面
#修改以下内容
regtest=1
server=1
rpcuser=admin1
rpcpassword=123
rpcallowip=0.0.0.0/0
rpcport=8001
dnsseed=0
upnp=0
port=8000
#修改以下内容
regtest=1
connect=172.16.172.90:8000
listen=0
server=1
rpcuser=admin2
rpcpassword=123
rpcallowip=0.0.0.0/0
rpcport=9001
dnsseed=0
upnp=0
port=9000
启动服务
./bitcoind -daemon -datadir=1
./bitcoind -daemon -datadir=2
查询服务
./bitcoin-cli -datadir=1 getwalletinfo
{
"walletname": "wallet.dat",
"walletversion": 159900,
"balance": 0.00000000,
"unconfirmed_balance": 0.00000000,
"immature_balance": 0.00000000,
"txcount": 0,
"keypoololdest": 1523884293,
"keypoolsize": 1000,
"keypoolsize_hd_internal": 1000,
"paytxfee": 0.00000000,
"hdmasterkeyid": "3667dcf4ebe66ee13f38ab76d1e87e32580d188c"
}
./bitcoin-cli -datadir=1 getnetworkinfo
{
"version": 160000,
"subversion": "/Satoshi:0.16.0/",
"protocolversion": 70015,
"localservices": "000000000000040d",
"localrelay": true,
"timeoffset": 0,
"networkactive": true,
"connections": 1,
"networks": [
{
"name": "ipv4",
"limited": false,
"reachable": true,
"proxy": "",
"proxy_randomize_credentials": false
},
{
"name": "ipv6",
"limited": false,
"reachable": true,
"proxy": "",
"proxy_randomize_credentials": false
},
{
"name": "onion",
"limited": true,
"reachable": false,
"proxy": "",
"proxy_randomize_credentials": false
}
],
"relayfee": 0.00001000,
"incrementalfee": 0.00001000,
"localaddresses": [
],
"warnings": ""
}
./bitcoin-cli -datadir=1 getblockchaininfo
{
"chain": "regtest",
"blocks": 0,
"headers": 0,
"bestblockhash": "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",
"difficulty": 4.656542373906925e-10,
"mediantime": 1296688602,
"verificationprogress": 1,
"initialblockdownload": true,
"chainwork": "0000000000000000000000000000000000000000000000000000000000000002",
"size_on_disk": 293,
"pruned": false,
"softforks": [
{
"id": "bip34",
"version": 2,
"reject": {
"status": false
}
},
{
"id": "bip66",
"version": 3,
"reject": {
"status": false
}
},
{
"id": "bip65",
"version": 4,
"reject": {
"status": false
}
}
],
"bip9_softforks": {
"csv": {
"status": "defined",
"startTime": 0,
"timeout": 9223372036854775807,
"since": 0
},
"segwit": {
"status": "active",
"startTime": -1,
"timeout": 9223372036854775807,
"since": 0
}
},
"warnings": ""
}
./bitcoin-cli -datadir=2 getwalletinfo
{
"walletname": "wallet.dat",
"walletversion": 159900,
"balance": 0.00000000,
"unconfirmed_balance": 0.00000000,
"immature_balance": 0.00000000,
"txcount": 0,
"keypoololdest": 1523884295,
"keypoolsize": 1000,
"keypoolsize_hd_internal": 1000,
"paytxfee": 0.00000000,
"hdmasterkeyid": "4e5293f045709dcf70fae832c60d9ffa5f1eedd3"
}
./bitcoin-cli -datadir=2 getnetworkinfo
{
"version": 160000,
"subversion": "/Satoshi:0.16.0/",
"protocolversion": 70015,
"localservices": "000000000000040d",
"localrelay": true,
"timeoffset": 0,
"networkactive": true,
"connections": 1,
"networks": [
{
"name": "ipv4",
"limited": false,
"reachable": true,
"proxy": "",
"proxy_randomize_credentials": false
},
{
"name": "ipv6",
"limited": false,
"reachable": true,
"proxy": "",
"proxy_randomize_credentials": false
},
{
"name": "onion",
"limited": true,
"reachable": false,
"proxy": "",
"proxy_randomize_credentials": false
}
],
"relayfee": 0.00001000,
"incrementalfee": 0.00001000,
"localaddresses": [
],
"warnings": ""
}
./bitcoin-cli -datadir=2 getblockchaininfo
{
"chain": "regtest",
"blocks": 0,
"headers": 0,
"bestblockhash": "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206",
"difficulty": 4.656542373906925e-10,
"mediantime": 1296688602,
"verificationprogress": 1,
"initialblockdownload": true,
"chainwork": "0000000000000000000000000000000000000000000000000000000000000002",
"size_on_disk": 293,
"pruned": false,
"softforks": [
{
"id": "bip34",
"version": 2,
"reject": {
"status": false
}
},
{
"id": "bip66",
"version": 3,
"reject": {
"status": false
}
},
{
"id": "bip65",
"version": 4,
"reject": {
"status": false
}
}
],
"bip9_softforks": {
"csv": {
"status": "defined",
"startTime": 0,
"timeout": 9223372036854775807,
"since": 0
},
"segwit": {
"status": "active",
"startTime": -1,
"timeout": 9223372036854775807,
"since": 0
}
},
"warnings": ""
}
产生200个区块
./bitcoin-cli -datadir=1 generate 200
[
"10f2e86ef528fae6f21f57f3136e3d6b8c07c86a3c044376c613855d8a080dd8",
"5621bbd0a9748a11998dc2c490b616331464ce61af3de7e7d45f6ecf4b0a5bc8",
]
#节点1里面有5000个币了
./bitcoin-cli --datadir=1 getwalletinfo
{
"walletname": "wallet.dat",
"walletversion": 159900,
"balance": 5000.00000000,
"unconfirmed_balance": 0.00000000,
"immature_balance": 3725.00000000,
"txcount": 200,
"keypoololdest": 1523884293,
"keypoolsize": 999,
"keypoolsize_hd_internal": 1000,
"paytxfee": 0.00000000,
"hdmasterkeyid": "3667dcf4ebe66ee13f38ab76d1e87e32580d188c"
获取钱包地址
./bitcoin-cli --datadir=1 getaccountaddress ""
2NFZnKjdTEBnkT5LS74eucKVATP76xR3HvM
./bitcoin-cli --datadir=2 getaccountaddress ""
2MxcGwmqT73Nra6NM6S43RcZPPYbkBLdyCt
转账
#节点1向节点2转账10个币
./bitcoin-cli -datadir=1 sendtoaddress "2MxcGwmqT73Nra6NM6S43RcZPPYbkBLdyCt" 10
0f502f7ebbe1a043eba540adbf481b368a7a77708bae42489f590ac1bcffbaee
#节点1产生10个区块,确保交易完成
./bitcoin-cli -datadir=1 generate 10
[
"7075d3c76160136b80d0347291b7264ed32d0874bee98ac4375b19ee152c29f1",
"27d8745b7eca9e9a938a84a2221519743671f5ebc6a1bee56b11859832a4340a",
"782c01957823ad873afd5a2074e76006734f3fb12266f162840b3e008af33025",
"18b723bcd44be3c0bb822adffc0b042cfd7b5a908f7d81d8a1b610e58cb43a49",
"150f3987aad99f1ce4114a0bfdcc9f2ec7e70c20daf91708c21869dae66d38e9",
"5575fe86b535a6d965d334dba53165f73b701c6f28d763429d581e80800737a8",
"33f6dd92dbad895398b01fff686a72ec1066d65c8d502fed43e7698dab631d92",
"41ba97be18e22cc16a8f27086ab849fa5e6e8baaa33b0c9bb4ff73de1a5665be",
"60b9cddc7255897398e8a3febf5418ef1a1184788cf7ef82f9fc9d1c929b90ae",
"0a1870aab4ef206a9d270eb0c3fe46fe7dcc60f1a6d15b6a4e1f7e5c14d02250"
]
#节点2收到10个币
./bitcoin-cli --datadir=2 getwalletinfo
{
"walletname": "wallet.dat",
"walletversion": 159900,
"balance": 10.00000000,
"unconfirmed_balance": 0.00000000,
"immature_balance": 0.00000000,
"txcount": 0,
"keypoololdest": 1523884295,
"keypoolsize": 999,
"keypoolsize_hd_internal": 1000,
"paytxfee": 0.00000000,
"hdmasterkeyid": "4e5293f045709dcf70fae832c60d9ffa5f1eedd3"
}
#节点2的区块同样为210个
./bitcoin-cli --datadir=2 getblockchaininfo
{
"chain": "regtest",
"blocks": 210,
"headers": 210,
"bestblockhash": "0a1870aab4ef206a9d270eb0c3fe46fe7dcc60f1a6d15b6a4e1f7e5c14d02250",
"difficulty": 4.656542373906925e-10,
"mediantime": 1523884432,
"verificationprogress": 1,
"initialblockdownload": false,
"chainwork": "00000000000000000000000000000000000000000000000000000000000001a6",
"size_on_disk": 66105,
"pruned": false,
"softforks": [
{
"id": "bip34",
"version": 2,
"reject": {
"status": false
}
},
{
"id": "bip66",
"version": 3,
"reject": {
"status": false
}
},
{
"id": "bip65",
"version": 4,
"reject": {
"status": false
}
}
],
"bip9_softforks": {
"csv": {
"status": "started",
"bit": 0,
"startTime": 0,
"timeout": 9223372036854775807,
"since": 144,
"statistics": {
"period": 144,
"threshold": 108,
"elapsed": 67,
"count": 67,
"possible": true
}
},
"segwit": {
"status": "active",
"startTime": -1,
"timeout": 9223372036854775807,
"since": 0
}
},
"warnings": ""
}
最后更新于