Neurotic and Probably Misinformed
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

bitcoin-lightning-nodejs

1.1.3 • Public • Published

Bitcoin Lightning Client

Welcome to the implementation of gRPC API reference documentation for LND in Nodejs , the Lightning Network Daemon.

The examples in this repo assume that the there is a local lnd instance running and listening for gRPC connections on port 10009. LND_DIR will be used as a placeholder to denote the base directory of the lnd instance. By default, this is ~/.lnd on Linux and ~/Library/Application Support/Lnd on macOS.

Lightning Network Daemon Installation: https://dev.lightning.community/guides/installation/

Concepts: https://dev.lightning.community/overview/

What is this package for?

This package is for developers who want to integrate Bitcoin lightning Network in their app using nodejs.

How do I get set up?

  • npm i bitcoin-lightning-nodejs
  • make sure you have node installed on your machine

How to setup tls.cert, macaroon.admin , channel host ?

Check https://gitlab.com/coinsafedev/bitcoin-lightning-nodejs/blob/master/auth.js

Table of contents


GenSeed

GenSeed is the first method that should be used to instantiate a new lnd instance. This method allows a caller to generate a new aezeed cipher seed given an optional passphrase. If provided, the passphrase will be necessary to decrypt the cipherseed to expose the internal wallet seed. Once the cipherseed is obtained and verified by the user, the InitWallet method should be used to commit the newly generated seed, and create the wallet.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.generateSeed(paraphrase, seed_entropy, (err , res) => {
 
});

Initiate Wallet

InitWallet is used when lnd is starting up for the first time to fully initialize the daemon and its internal wallet. At the very least a wallet password must be provided. This will be used to encrypt sensitive material on disk. In the case of a recovery scenario, the user can also specify their aezeed mnemonic and passphrase. If set, then the daemon will use this prior state to initialize its internal wallet. Alternatively, this can be used along with the GenSeed RPC to obtain a seed, then present it to the user. Once it has been verified by the user, the seed can be fed into this RPC in order to commit the new wallet.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.initiateWallet(wallet_password , cipher_seed_mnemonic, paraphrase, recovery_window, (err , res) => {
 
});
 

Unlock Wallet

UnlockWallet is used at startup of lnd to provide a password to unlock the wallet database.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.unlockWalletRequest(wallet_password ,recovery_window, (err , res) => {
 
});
 

Change Wallet Password

ChangePassword changes the password of the encrypted wallet. This will automatically unlock the wallet database if successful.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.changeWalletPassword(current_password , new_password, (err , res) => {
 
});
 

Wallet Balance

WalletBalance returns total unspent outputs(confirmed and unconfirmed), all confirmed unspent outputs and all unconfirmed unspent outputs under control of the wallet.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.walletBalanceRequest();
 

Channel Balance

ChannelBalance returns the total funds available across all open channels in satoshis.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.channelBalanceRequest();
 

Get Transactions

GetTransactions returns a list describing all the known transactions relevant to the wallet.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.getTransactionsRequest();
 

Send Coins

SendCoins executes a request to send coins to a particular address. Unlike SendMany, this RPC call only allows creating a single output at a time. If neither target_conf, or sat_per_byte are set, then the internal wallet will consult its fee model to determine a fee for the default confirmation target.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.sendCoinsRequest(addr , amount , target_conf, sat_per_byte, (err , res) => {
 
});
 

Subscribe Trasactions

SubscribeTransactions creates a uni-directional stream from the server to the client in which any newly discovered transactions relevant to the wallet are sent over.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.getTransactionsRequest();
 

Send Multiple Requests

SendMany handles a request for a transaction that creates multiple specified outputs in parallel. If neither target_conf, or sat_per_byte are set, then the internal wallet will consult its fee model to determine a fee for the default confirmation target.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.sendManyRequest(AddrToAmount, target_conf, sat_per_byte, (err , res) => {
 
});
 

New Address

NewAddress creates a new address under control of the local wallet.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.newAddressRequest(type, (err , res) => {
 
});
 

Sign Message

SignMessage signs a message with this node’s private key. The returned signature string is zbase32 encoded and pubkey recoverable, meaning that only the message digest and signature are needed for verification.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.signMessageRequest(msg, (err , res) => {
 
});
 

Verify Message

VerifyMessage verifies a signature over a msg. The signature must be zbase32 encoded and signed by an active node in the resident node’s channel database. In addition to returning the validity of the signature, VerifyMessage also returns the recovered pubkey from the signature.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.verifyMessageRequest(msg , signature, (err , res) => {
 
});
 

Connect Peer

ConnectPeer attempts to establish a connection to a remote peer. This is at the networking level, and is used for communication between nodes. This is distinct from establishing a channel with a peer.

var lightning = require('bitcoin-lightning-nodejs');
 
lightning.connectPeer(addr , perm, (err , res) => {
 
});
 

Donating

Bitcoin Address: 14AaoxQLQ92rpMsXSKPAYs5yetCLkB64KF

Ether Address: 0x92c0ba99b59dba211b70de410ab3513bd25de408

Core Contributor

install

npm i bitcoin-lightning-nodejs

Downloadsweekly downloads

46

version

1.1.3

license

ISC

last publish

collaborators

  • avatar
Report a vulnerability