本文作者:陳進堅
個人博客: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_api
和https://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