Ubuntu莱特币私有链搭建

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

安装litecoind

在官网https://litecoin.org/中找到合适的版本,复制链接后下载,版本必须是0.16以上,否则有些新的命令无法使用

root@ubuntu:~# wget https://download.litecoin.org/litecoin-0.17.1/linux/litecoin-0.17.1-x86_64-linux-gnu.tar.gz
root@ubuntu:~# tar zxf litecoin-0.17.1-x86_64-linux-gnu.tar.gz

创建软连接

root@ubuntu:~# ln -fs /root/litecoin-0.17.1/bin/litecoind /usr/local/bin/litecoind
root@ubuntu:~# ln -fs /root/litecoin-0.17.1/bin/litecoin-cli /usr/local/bin/litecoin-cli
root@ubuntu:~# install -m 0755 -o root -g root -t /usr/local/bin ./litecoin-0.17.1/bin/*

检查版本号

root@ubuntu:~# litecoind --version

配置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/bitcoin-core-config-generator/

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

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

# Username for JSON-RPC connections
rpcuser=bitcoinrpc

# Password for JSON-RPC connections
rpcpassword=bitcoinrpc

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

# 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

# 设定默认为私有链
regtest=1

启动litecoin程序

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

-deamon表示后台运行

停止litecoin程序

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

访问Json-RPC接口

在主网(mainnet)和测试网络(testnet)模式下json-rpc端口是使用.litecoin/litecoin.conf中配置的19332端口进行访问,但是在私有链(regtest)模式下似乎配置了并没有作用,还是要访问默认的19443端口。

我们可以使用postman或者curl等工具进行访问:litecoinrpc:litecoinrpc分别是rpc用户名和密码

curl -s -X POST --user litecoinrpc:litecoinrpc  -H 'content-type: text/plain;' http://127.0.0.1:19443/   --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getnetworkinfo", "params": [] }'

更多RPC方法可以参考https://www.blockchain.com/es/api/json_rpc_apihttps://litecoin-rpc.github.io/en/doc/0.17.99/rpc/

litecoin-cli常用命令

查看钱包信息

该命令可以获取到钱包版本、余额、交易数量等信息

litecoin-cli getwalletinfo

获取所有钱包地址及其账号名

bitcoin-cli listreceivedbyaddress 1 true

查询余额

bitcoin-cli getbalance

注意:查询得到的余额是所有钱包地址的可用余额总和,并且不包含私钥不在节点的钱包地址余额。

生成钱包地址

litecoin-cli getnewaddress "test"  #"test"是输入的账号

查询地址收到币的数量

litecoin-cli getreceivedbyaddress 2MtmeZ7W17zJzigtRhzKMP6MSc2DSyL5LYU

命令列表

bitcoin-cli help

猜你喜欢

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