Litecoin-CLI Commands

A list of some frequently needed Litecoin commands for my reference (for use with litecoin-cli on Linux).

Table Of Contents
Litecoin CLI Commands
The JSON RPC API

JSON RPC Headers

You can get started with the JSON RPC API using the Authorization and Content-Type headers, similar to the ones shown below. The request method is ‘POST’, as the RPC API requires POST requests (which are more private than GET requests).

{
    'Content-Type': 'application/json',
    'Authorization': 'Basic [code]'
}

Litecoin CLI Commands

List commands (don’t use a hyphen behind help):

./litecoin-cli help

General help screen:

./litecoin-cli -?

Start the Litecoin daemon/start your full node (do this before running the litecoin-cli commands that follow):

litecoind

Create a new Litecoin address:

./litecoin-cli getnewaddress exampleusername1

List the Litecoin transactions for a user (exampleusername1 in this case):

./litecoin-cli listtransactions exampleusername1

List transactions using the JSON RPC API:

{"jsonrpc":"1.0","id":"rpc","method":"listtransactions", "params":["username"]}

Retrieve LTC balance:

./litecoin-cli getbalance exampleusername1

Retrieve LTC balance using the JSON RPC API:

{"jsonrpc":"1.0","id":"rpc","method":"getbalance", "params":[]}

How to send LTC using the CLI:

./litecoin-cli sendfrom exampleusername1 ltcaddress amountinltc

Get the details for a particular LTC transaction including the amount, the fee, time received, whether it was sent or received, among numerous other details (this is for your own transactions, though):

./litecoin-cli gettransaction transactionid

Get the amount received by an address:

./litecoin-cli getreceivedbyaddress ltcaddress

Get information about connected nodes:

./litecoin-cli getpeerinfo

Export Your Litecoin Private Key (Get Your Private Key From Litecoin Core For Backup Purposes):

./litecoin-cli dumpwallet privatekey.txt

Always copy the key to a USB drive that is not used by you or anyone else, and stow it away in a safe place.

Note that if you encrypted your wallet with a password, you will need to unlock it before exporting your private key. One way to do it is by typing the following:

./litecoin-cli walletpassphrase "yourpassword" 200

Now that you have entered your password in a shell/command prompt. You will need to clear its history for security purposes. One way you can do that on Linux is by typing

history -c

Get info about a particular block such as the transactions it contains, block height, block size, confirmations, among other things:

./litecoin-cli getblock [block_hash]

Get info about a block via the JSON RPC API:

{"jsonrpc":"1.0","id":"rpc","method":"getblock", "params":["hash"]}

Litecoin RPC API Tips

If you want to use the Litecoin JSON RPC API, the Litecoin daemon (litecoind) accepts connections on port 9332 and commands can be issued to it via HTTP POST requests. The Litecoin JSON RPC API has the method field in which you could put the getbalance, listtransactions, and other commands like those mentioned in the CLI examples above. It also has a params field in which you coud put the username:

For example, the values could be:

method: getbalance

params: exampleusername1

You can set the API’s username and password by creating a litecoin.conf file (if there isn’t already one) and placing the following lines in it (you don’t have to use the same username in your wallet account):

rpcuser=yourusername
rpcpassword=yourpassword

In order to connect on the same machine, you may want to add the following lines to allow connections from localhost:

rpcbind=127.0.0.1
rpcallowip=127.0.0.0/24

You can change the port that the Litecoin server/daemon listens on by setting it in the rpcport field as shown in the example below:

rpcport=9334