本文作者:陈进坚
博客地址:https://jian1098.github.io
CSDN博客:https://blog.csdn.net/c_jian
简书:https://www.jianshu.com/u/8ba9ac5706b6
联系方式:jian1098@qq.com
安装bitcoin核心
1 | root@ubuntu:~# sudo apt-get install software-properties-common |
配置bitcoin参数
1 | root@ubuntu:~$ mkdir .bitcoin #创建目录 |
将下面信息全部复制,并修改rpcuser(RPC用户名),rpcpassword(RPC用户密码),rpcallowip(允许访问的ip地址)然后保存
1 | # Generated by https://jlopp.github.io/bitcoin-core-config-generator/ |
启动bitcoin程序
1 | root@ubuntu:~/.bitcoin$ bitcoind -daemon |
查看是否启动成功,需要输入上一步配置的密码,用户名bitcoinrpc改为你配置的用户名:
1 | root@ubuntu:~$ curl --user bitcoinrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnetworkinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ |
能返回下面的信息表示启动成功
1 | {"result":{"version":170000,"subversion":"/Satoshi:0.17.0/","protocolversion":70015,"localservices":"000000000000040d","localrelay":true,"timeoffset":0,"networkactive":true,"connections":5,"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":""},"error":null,"id":"curltest"} |
停止bitcoin程序
1 | root@ubuntu:~/.bitcoin/testnet3$ bitcoin-cli stop |
检查区块同步信息
检查同步日志(刷屏):
1 | root@ubuntu:~/.bitcoin$ cd testnet3/ |
查询当前同步到的区块数:
1 | root@ubuntu:~$ curl --user bitcoinrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ |
查询测试网络中的总区块:https://live.blockcypher.com/btc-testnet/
需要注意的是只有区块同步到最新才可以查到钱包余额,从头开始同步大概需要一天时间。
创建钱包地址
1 | root@ubuntu:~$ curl --user bitcoinrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": ["test"] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ |
返回结果中的 “2MyUBCnC2FvwX6ihegTVCKn1iKc5JeyEbKr” 即为新创建的比特币钱包,以2开头表示是测试链的钱包地址,公链上的钱包地址一般是3开头
查询余额
1 | omni@ubuntu:~$ curl --user bitcoinrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ |
获取测试币
在下面两个网站中可以获得少量的测试币,用来测试足够了:
https://coinfaucet.eu/en/btc-testnet/
http://bitcoinfaucet.uo1.net/send.php
你可以在比特币区块链浏览器查到余额:https://live.blockcypher.com/btc-testnet/address/2MtW8kA68TMrBLZb373WttjHbxfuRNdvHh7/