Ubuntu莱特币测试环境搭建

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/C_jian/article/details/84338369

本文作者:陈进坚
博客地址:https://jian1098.github.io
CSDN博客:https://blog.csdn.net/c_jian
简书:https://www.jianshu.com/u/8ba9ac5706b6
联系方式:[email protected]

安装litecoin核心

root@ubuntu:~# wget https://download.litecoin.org/litecoin-0.16.3/linux/litecoin-0.16.3-x86_64-linux-gnu.tar.gz
root@ubuntu:~# tar -zvxf litecoin-0.16.3-x86_64-linux-gnu.tar.gz 
root@ubuntu:~# install -m 0755 -o root -g root -t /usr/local/bin ./litecoin-0.16.3/bin/*

配置litecoin参数

root@ubuntu:~$ mkdir .litecoin	#创建目录
root@ubuntu:~$ cd .litecoin/
root@ubuntu:~$ vi litecoin.conf

将下面信息全部复制,并修改rpcuser(RPC用户名),rpcpassword(RPC用户密码),rpcallowip(允许访问的ip地址)然后保存

# Generated by https://jlopp.github.io/litecoin-core-config-generator/

# This config should be placed in following path:
# ~/.litecoin/litecoin.conf

# [rpc]
# Accept command line and JSON-RPC commands.
server=1

# Username for JSON-RPC connections
rpcuser=litecoinrpc

# Password for JSON-RPC connections
rpcpassword=litecoinrpc

# Listen for JSON-RPC connections on this port
rpcport=18332

# Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), 
# a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option 
# can be specified multiple times.
rpcallowip=192.168.1.178
rpcallowip=192.168.1.179

# Run this node on the litecoin Test Network.
testnet=1

启动litecoin程序

root@ubuntu:~/.litecoin$ litecoind -daemon
Litecoin server starting

查看是否启动成功,需要输入上一步配置的密码,用户名litecoinrpc改为你配置的用户名:

root@ubuntu:~$ curl --user litecoinrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnetworkinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/
Enter host password for user 'litecoinrpc':

能返回下面的信息表示启动成功

{"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"}

停止litecoin程序

root@ubuntu:~/.litecoin/testnet3$ litecoin-cli stop
Litecoin server stopping

检查区块同步信息

检查同步日志(刷屏):

root@ubuntu:~/.litecoin$ cd testnet4/
root@ubuntu:~/.litecoin/testnet3$ tail -f debug.log 
2018-11-21T02:40:28Z net thread start
2018-11-21T02:40:31Z New outbound peer connected: version: 70015, blocks=1444366, peer=1
2018-11-21T02:40:31Z New outbound peer connected: version: 70015, blocks=1444366, peer=0
2018-11-21T02:40:32Z 108 addresses found from DNS seeds
2018-11-21T02:40:32Z dnsseed thread exit
2018-11-21T02:40:36Z New outbound peer connected: version: 70015, blocks=1444366, peer=2
2018-11-21T02:40:37Z New outbound peer connected: version: 70015, blocks=1444366, peer=5
2018-11-21T02:40:37Z New outbound peer connected: version: 70015, blocks=1444366, peer=3
2018-11-21T02:40:41Z New outbound peer connected: version: 70015, blocks=1444366, peer=4
2018-11-21T02:40:48Z New outbound peer connected: version: 70015, blocks=1414448, peer=6
.......

查询当前同步到的区块数:

root@ubuntu:~/.litecoin/testnet4$ curl --user litecoinrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/

Enter host password for user 'litecoinrpc':
{"result":128631,"error":null,"id":"curltest"}

查询测试网络中的总区块:http://testnet.litecointools.com/

需要注意的是只有区块同步到最新才可以查到钱包余额,从头开始同步大概需要一天时间。

创建钱包地址

root@ubuntu:~$ curl --user litecoinrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnewaddress", "params": ["test"] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/
Enter host password for user 'litecoinrpc':
{"result":"QNuZnYa45hWRpsJz4SYwAEQfZS9UBc2j6L","error":null,"id":"curltest"}  

返回结果中的 “QNuZnYa45hWRpsJz4SYwAEQfZS9UBc2j6L” 即为新创建的莱特币钱包地址

查询余额

omni@ubuntu:~$ curl --user litecoinrpc --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/

获取测试币

在下面两个网站中可以获得少量的测试币,用来测试足够了:

http://testnet.litecointools.com/
https://faucet.xblau.com/

你可以在莱特币区块链浏览器查到余额

http://explorer.litecointools.com/address/QNuZnYa45hWRpsJz4SYwAEQfZS9UBc2j6L

猜你喜欢

转载自blog.csdn.net/C_jian/article/details/84338369