Mac OS X 系统下莱特币 ( LTC ) 官方钱包的命令行程序安装

yufei       6 年, 2 月 前       4345

莱特币 号称轻量级的比特币。不过也没比比特币简单多少。我看中它的原因是它的数据量大小只有 20G 左右,再其它数字火币大小暴涨的今天,也算是一个良心币了。

莱特币的官方钱包 Mac 版有一个 .dmg ,如果你只是使用而已的话就直接安装 DMG 格式的就好。

如果你是开发,需要调用 RPC 接口,我的推荐方式,就是安装它们的命令行程序。

因为笔者的电脑是 MAC,也就是苹果笔记本,所以我们就介绍下 OSX 系统下如何安装吧

前期准备

  1. 首先你的必须有一台空余硬盘 30+G 的笔记本。虽然莱特币目前只有 20G 左右,但是加上索引等七七八八的,也不小了

  2. 已经安装了 HomeBrew ,官方地址为 https://brew.sh/

  3. 熟悉终端,也称之为 Shell

安装依赖

打开终端,输入以下命令安装一些前置依赖

brew install automake berkeley-db4 libtool boost miniupnpc openssl pkg-config protobuf python3 qt libevent libtool

下载代码

最新的 LiteCoin 代码都托管在 Github

你可以点击下载 zip 版本或者使用下面的命令拷贝到本地

git clone https://github.com/litecoin-project/litecoin

下载完成后使用 cd litecoin 命令进入 litecoin 目录

编译安装

  1. 首先使用下面的命令生成预编译 configure 相关文件

    ./autogen.sh
    
  2. 然后使用下面的命令生成预编译指令

    ./configure
    
  3. 然后就可以使用 make 命令来编译了,编译很耗时,而且事故多发

    make
    
  4. 检测我们的编译情况

    make check
    
  5. 其实这时候已经可以使用了,已经可以在 ./src 目录看到以下三个二进制可执行文件

    litecoind
    litecoin-cli
    litecoin-tx
    

    各个文件的作用如下

    文件 说明
    litecoind Litecoin 钱包守护进程文件
    litecoin-cli Litecoin RPC 客户端
    litecoin-tx 用于生成一个交易记录,一般用不着
  6. 为了方便日后的运行,我们需要将上述三个文件复制到 /usr/local/bin 目录下

    cd ~/litecoin/src
    cp litecoind /usr/local/bin
    cp litecoind-cli /usr/local/bin/
    cp litecoind-tx  /usr/local/bin/
    

    或者使用下面的命令进行安装

    make install
    

配置文件

在运行守护进程 litecoind 之前,我们先需要配置一下配置文件,以防止日后需要重新配置的时候需要重新下载

Litecoid 比特币默认的存储目录为

/Users/${USER}/Library/Application Support/Litecoin

如果你的 User 目录硬盘足够,其实可以不用做下面的软链接,因为我的不够,所用了第二块硬盘,该硬盘挂在到 /Volumes/backup ,所以我做了一个软链接

ln -s /Volumes/backup/litecoin/data /Users/${USER}/Library/Application Support/Litecoin

然后在 /Volumes/backup/litecoin/data 目录下新建一个文件 litecoind.conf 并输入一下内容

txindex=1
rpcuser=yufei
rpcpassword=110220
daemon=1
datadir=/Volumes/backup/litecoin/data

还有更多信息,我们这里只是列出了几个重要的

选项 说明
txindex 1 索引全部交易数据,默认为 0 ,只会索引最近的交易信息
rpcuser yufei RPC JSON 调用时,应该输入的用户名
rpcpassword 110220 RPC JSON 调用时,应该输入的密码
daemon 1 开启守护进程模式,如果不设置则为前台运行

运行 Litecoin 守护进程

如果你只是访问钱包和使用钱包,则不用配置上面的 litecoin.conf 文件,直接运行 litecond 即可

[root@localhost src] ./litecoind
Litecoin server starting

这样,就启动了我们的 litecoind 守护进程文件

对了,所有的配置都可以使用 litecoin.conf 来覆盖

而所有的 litecoin.conf 配置项也可以通过命令行参数来覆盖,除了 --conf 等几个少数的选项。

同步数据

运行上述的文件就,就会开始同步区块数据,因为 17G+ 数据需要同步,所以可能需要很长时间

使用 litecoin-cli 脚本访问远程 RPC JSON 服务

我们可以使用下面的命令 litecoin-cli 命令查看 litecoin-cli 提供了哪些选项

[yufei@www.twle.cn all]$ litecoin-cli --help
Litecoin Core RPC client version v0.16.2

Usage:
  litecoin-cli [options] <command> [params]  Send command to Litecoin Core
  litecoin-cli [options] -named <command> [name=value] ... Send command to Litecoin Core (with named arguments)
  litecoin-cli [options] help                List commands
  litecoin-cli [options] help <command>      Get help for a command

Options:

  -?
       This help message

  -conf=<file>
       Specify configuration file (default: litecoin.conf)

  -datadir=<dir>
       Specify data directory

  -getinfo
       Get general information from the remote server. Note that unlike
       server-side RPC calls, the results of -getinfo is the result of
       multiple non-atomic requests. Some entries in the result may
       represent results from different states (e.g. wallet balance may
       be as of a different block from the chain state reported)

Chain selection options:

  -testnet
       Use the test chain

  -regtest
       Enter regression test mode, which uses a special chain in which blocks
       can be solved instantly. This is intended for regression testing
       tools and app development.

  -named
       Pass named instead of positional arguments (default: false)

  -rpcconnect=<ip>
       Send commands to node running on <ip> (default: 127.0.0.1)

  -rpcport=<port>
       Connect to JSON-RPC on <port> (default: 9332 or testnet: 19332)

  -rpcwait
       Wait for RPC server to start

  -rpcuser=<user>
       Username for JSON-RPC connections

  -rpcpassword=<pw>
       Password for JSON-RPC connections

  -rpcclienttimeout=<n>
       Timeout in seconds during HTTP requests, or 0 for no timeout. (default:
       900)

  -stdinrpcpass
       Read RPC password from standard input as a single line.  When combined
       with -stdin, the first line from standard input is used for the
       RPC password.

  -stdin
       Read extra arguments from standard input, one per line until EOF/Ctrl-D
       (recommended for sensitive information such as passphrases). 
       When combined with -stdinrpcpass, the first line from standard
       input is used for the RPC password.

  -rpcwallet=<walletname>
       Send RPC for non-default wallet on RPC server (argument is wallet
       filename in litecoind directory, required if litecoind/-Qt runs
       with multiple wallets)

如果要查看当前可以使用哪些 RPC 指令,那么可以使用 litecoin-cli help 方法

[yufei@www.twle.cn all]$ litecoin-cli help
== Blockchain ==
getbestblockhash
getblock "blockhash" ( verbosity ) 
getblockchaininfo
getblockcount
getblockhash height
getblockheader "hash" ( verbose )
getchaintips
getchaintxstats ( nblocks blockhash )
getdifficulty
getmempoolancestors txid (verbose)
getmempooldescendants txid (verbose)
getmempoolentry txid
getmempoolinfo
getrawmempool ( verbose )
gettxout "txid" n ( include_mempool )
gettxoutproof ["txid",...] ( blockhash )
gettxoutsetinfo
preciousblock "blockhash"
pruneblockchain
savemempool
verifychain ( checklevel nblocks )
verifytxoutproof "proof"

== Control ==
getmemoryinfo ("mode")
help ( "command" )
logging ( <include> <exclude> )
stop
uptime

== Generating ==
generate nblocks ( maxtries )
generatetoaddress nblocks address (maxtries)

== Mining ==
getblocktemplate ( TemplateRequest )
getmininginfo
getnetworkhashps ( nblocks height )
prioritisetransaction <txid> <dummy value> <fee delta>
submitblock "hexdata"  ( "dummy" )

== Network ==
addnode "node" "add|remove|onetry"
clearbanned
disconnectnode "[address]" [nodeid]
getaddednodeinfo ( "node" )
getconnectioncount
getnettotals
getnetworkinfo
getpeerinfo
listbanned
ping
setban "subnet" "add|remove" (bantime) (absolute)
setnetworkactive true|false

== Rawtransactions ==
combinerawtransaction ["hexstring",...]
createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,"data":"hex",...} ( locktime ) ( replaceable )
decoderawtransaction "hexstring" ( iswitness )
decodescript "hexstring"
fundrawtransaction "hexstring" ( options iswitness )
getrawtransaction "txid" ( verbose "blockhash" )
sendrawtransaction "hexstring" ( allowhighfees )
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )

== Util ==
createmultisig nrequired ["key",...]
estimatefee nblocks
estimatesmartfee conf_target ("estimate_mode")
signmessagewithprivkey "privkey" "message"
validateaddress "address"
verifymessage "address" "signature" "message"

== Wallet ==
abandontransaction "txid"
abortrescan
addmultisigaddress nrequired ["key",...] ( "account" "address_type" )
backupwallet "destination"
bumpfee "txid" ( options ) 
dumpprivkey "address"
dumpwallet "filename"
encryptwallet "passphrase"
getaccount "address"
getaccountaddress "account"
getaddressesbyaccount "account"
getbalance ( "account" minconf include_watchonly )
getnewaddress ( "account" "address_type" )
getrawchangeaddress ( "address_type" )
getreceivedbyaccount "account" ( minconf )
getreceivedbyaddress "address" ( minconf )
gettransaction "txid" ( include_watchonly )
getunconfirmedbalance
getwalletinfo
importaddress "address" ( "label" rescan p2sh )
importmulti "requests" ( "options" )
importprivkey "privkey" ( "label" ) ( rescan )
importprunedfunds
importpubkey "pubkey" ( "label" rescan )
importwallet "filename"
keypoolrefill ( newsize )
listaccounts ( minconf include_watchonly)
listaddressgroupings
listlockunspent
listreceivedbyaccount ( minconf include_empty include_watchonly)
listreceivedbyaddress ( minconf include_empty include_watchonly)
listsinceblock ( "blockhash" target_confirmations include_watchonly include_removed )
listtransactions ( "account" count skip include_watchonly)
listunspent ( minconf maxconf  ["addresses",...] [include_unsafe] [query_options])
listwallets
lockunspent unlock ([{"txid":"txid","vout":n},...])
move "fromaccount" "toaccount" amount ( minconf "comment" )
removeprunedfunds "txid"
rescanblockchain ("start_height") ("stop_height")
sendfrom "fromaccount" "toaddress" amount ( minconf "comment" "comment_to" )
sendmany "fromaccount" {"address":amount,...} ( minconf "comment" ["address",...] replaceable conf_target "estimate_mode")
sendtoaddress "address" amount ( "comment" "comment_to" subtractfeefromamount replaceable conf_target "estimate_mode")
setaccount "address" "account"
settxfee amount
signmessage "address" "message"
walletlock
walletpassphrase "passphrase" timeout
walletpassphrasechange "oldpassphrase" "newpassphrase"

可以看到有非常多的指令,现在,我们首先看看最新的区块高度是多少,这得使用 litecoin-cli getblockcount 指令

[yufei@www.twle.cn all]$ litecoin-cli getblockcount
1483468

如果你对某个指令不熟悉,比如 getblockcount ,可以使用 litecoin-cli getblockcount 显示帮助信息

[yufei@www.twle.cn all]$ litecoin-cli help getblockcount
getblockcount

Returns the number of blocks in the longest blockchain.

Result:
n    (numeric) The current block count

Examples:
> litecoin-cli getblockcount 
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:9332/

其它命令也一样,因为我们的数据还未同步完成,所以就不掩饰数据方面的信息了

目前尚无回复
简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.