Node-litecoin
Template:Lowercasenode-litecoin is a simple Node.js wrapper for the Litecoin client's JSON-RPC API.
The API is equivalent to the Litecoin API document. The methods are exposed as lower camelcase methods on the litecoin.Client
object.
Contents
Install
npm install node-litecoin
Setup
- Traverse to
~/.litecoin
or~/Library/Application Support/Litecoin
and add a file calledlitecoin.conf
if it doesn't already exist. - Add these lines to the file, they are the login information for the server:
-
rpcuser=username
-
rpcpassword=password
-
- Start your Litecoin client with the
-server
argument or runlitecoind
- You should now be able to communicate with Litecoin JSON-RPC API using the node-litecoin library, try it out!
Examples
Create client
var litecoin = require('node-litecoin'); var client = new litecoin.Client({ host: 'localhost', port: 9332, user: 'username', pass: 'password' });
Create client with single object
var client = new litecoin.Client({ host: 'localhost', port: 9332, username: 'username', password: 'password' });
Get balance across all accounts with minimum confirmations of 6
client.getBalance('*', 6, function(err, balance) { if (err) console.log(err); console.log('Balance: ' + balance); });
Get the network hash rate
client.getNetworkHashPS(function(err, hashps) { if (err) console.log(err); console.log('Network Hash Rate: ' + hashps); });
SSL
If you're using this to connect to litecoind across a network it is highly recommended to enable ssl
, otherwise
an attacker may intercept your RPC credentials resulting in theft of your litecoins.
When enabling ssl
by setting the configuration option to true
, the sslStrict
option (verifies the server
certificate) will also be enabled by default. It is highly recommended to specify the sslCa
as well, even if your
litecoind has a certificate signed by an actual CA, to ensure you are connecting to your own litecoind.
var client = new litecoin.Client({ host: 'localhost', port: 8332, user: 'username', pass: 'password', ssl: true, sslStrict: true, sslCa: fs.readFileSync(__dirname + '/myca.cert') });