Methods for working with the Lightning Network
To connect to an LND node, authentication details are required.
Export credentials via CLI:
balanceofsatoshis:
npm install -g balanceofsatoshis
and export via bos credentials --cleartext
Or export them manually:
Run base64
on the tls.cert and admin.macaroon files to get the encoded
authentication data to create the LND connection. You can find these files in
the LND directory. (~/.lnd or ~/Library/Application Support/Lnd)
base64 ~/.lnd/tls.cert | tr -d '\n'
base64 ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon | tr -d '\n'
You can then use these to interact with your LND node directly:
const {authenticatedLndGrpc} = require('lightning');
const {lnd} = authenticatedLndGrpc({
cert: 'base64 encoded tls.cert file',
macaroon: 'base64 encoded admin.macaroon file',
socket: '127.0.0.1:10009',
});
To access unauthenticated methods like the wallet unlocker, use
unauthenticatedLndGrpc
instead.
There are two libraries, ln-service and this library.
Methods exported by this library support typescript, but ln-service includes additional metthods.
-
addPeer: Connect to a new peer
-
authenticatedLndGrpc: Instantiate connection to authenticated lnd methods.
-
broadcastChainTransaction: Publish an on-chain transaction to the network.
-
cancelHodlInvoice: Cancel an open invoice.
-
cancelPendingChannel: Cancel a pending channel.
-
closeChannel: Close a channel out to the chain.
-
changePassword: Update the wallet encryption passphrase.
-
connectWatchtower: Connect a new watchtower.
-
createChainAddress: Generate a chain address to receive on-chain funds.
-
createHodlInvoice: Make a new off-chain invoice that will not automatically accept payment.
-
createInvoice: Make a new off-chain invoice.
-
createSeed: Generate a random wallet HD seed.
-
createWallet: Make a new wallet.
-
decodePaymentRequest: Get parsed details for a payment request.
-
createWallet: Make a new wallet.
-
deleteFailedPayAttempts Remove failed payment paths from database.
-
deleteFailedPayments Remove failed payments from the database.
-
deleteForwardingReputations Clear pathfinding reputations of routing nodes and channels.
-
deletePayments: Remove all past payment records.
-
diffieHellmanComputeSecret: Calculate a shared secret to enable symmetric encryption of data to another node.
-
disableChannel: Signal disabled forwarding to a peer
-
disconnectWatchtower: Remove a connected watchtower
-
enableChannel: Signal forwarding enabled towards a peer.
-
fundPendingChannels: Provide a signed funding source for opening channels.
-
fundPsbt: Make a PSBT with funds and change to setup a future on-chain spend.
-
getAccessIds: List the access tokens granted permission to access the node.
-
getAutopilot: Retrieve channel open autopilot configuration.
-
getBackup: Get recovery details for a specific channel.
-
getBackups: Get recovery details for all channels.
-
getChainBalance: Get the amount of on-chain funds.
-
getChainFeeEstimate: Estimate a chain fee to send funds to an address.
-
getChainFeeRate: Get an estimate for an on-chain fee rate.
-
getChainTransactions: List past on-chain transactions.
-
getChannel: Lookup network graph details about a channel.
-
getChannelBalance: Calculate the total off-chain balance on the node.
-
getChannels: List open channels on the node.
-
getClosedChannels: List closed channels on the node.
-
getConnectedWatchtowers: List watchtowers that were added
-
getFeeRates: List routing fee rates and routing policies of channels on the node.
-
getForwardingConfidence: Calculate the pathfinding confidence score for routing a payment.
-
getForwardingReputations: List the pathfinding reputations for payment routing.
-
getForwards: List past forwards routed through the node.
-
getHeight: Lookup the current best chain height.
-
getIdentity: Derive the identity public key of the node.
-
getInvoice: Lookup the status of an invoice.
-
getInvoices: List details of all past open invoices and received payments.
-
getMethods: List RPC methods and permissions required to use them.
-
getNetworkCentrality: Calculate the graph centrality score of a node.
-
getNetworkGraph: List all graph routing nodes and all channels.
-
getNetworkInfo: Calculate network graph statistics.
-
getNode: Retrieve graph details for a node and optionally list its channels.
-
getPathfindingSettings: List out configuration options set for routing.
-
getPayment: Lookup details about a past payment.
-
getPayments: List details about past payment attempts and paid payment requests.
-
getPeers: List details of connected nodes.
-
getPendingChainBalance: Calculate the unconfirmed on-chain balance.
-
getPendingChannels: List details of opening or closing channels.
-
getPublicKey: Derive a public key at a given index.
-
getRouteThroughHops: Calculate a route through specified nodes.
-
getRouteToDestination: Calculate a route through the graph to a destination.
-
getSweepTransactions: List transactions that are sweeping funds on-chain.
-
getUtxos: List unspent transaction outputs in the on-chain wallet.
-
getWalletInfo: Lookup general details about the node.
-
getWalletVersion: Retrieve the version and build tags of the node.
-
grantAccess: Create an access credential macaroon to access the API.
-
isDestinationPayable: Check if a destination can be paid
-
lockUtxo: Lease a UTXO so it cannot be chosen to be spent.
-
openChannel: Create a new channel to another node.
-
openChannels: Open multiple channels in a single on-chain transaction batch.
-
pay: Make an off-chain payment.
-
payViaPaymentDetails: Pay off-chain using details about a destination invoice.
-
payViaPaymentRequest: Pay a payment request off-chain.
-
payViaRoutes: Pay to a destination using a specified route or routes.
-
prepareForChannelProposal: Prepare to receive a custom channel proposal.
-
probeForRoute: Run a probe to find a route to pay to a destination.
-
proposeChannel: Propose a new channel to a peer who has prepared for the channel proposal.
-
recoverFundsFromChannel: Attempt to recover channel funds from a specific channel backup.
-
recoverFundsFromChannels: Attempt to recover funds from multiple channels using a multiple channel backup.
-
removePeer: Disconnect from a connected peer.
-
revokeAccess: Remove the access privileges of a previously issued access token macaroon credential.
-
sendToChainAddress: Send funds on-chain to an address.
-
sendToChainAddresses: Send funds on-chain to multiple chain addresses.
-
setAutopilot: Set the open channel autopilot configuration settings.
-
settleHodlInvoice: Take incoming off-chain funds when an invoice has held funds from an incoming payment.
-
signBytes: Use node keys to sign over an arbitrary set of bytes.
-
signMessage: Use the node identity key to generate a signed message that represents the public graph node identity.
-
signPsbt: Sign inputs and finalize a partially signed transaction in the PSBT format to prepare it for broadcast.
-
signTransaction: Generate signatures required for inputs on a transaction.
-
stopDaemon: Send a shutdown request to cleanly kill the daemon.
-
subscribeToBackups: Get notified on channel funds recovery backup file updates.
-
subscribeToBlocks: Get notified when the Blockchain is updated.
-
subscribeToChainAddress: Get notified when funds are sent to an on-chain address.
-
subscribeToChainSpend: Get notified when a UTXO is spent.
-
subscribeToChannels: Get notified when the set of active channels is updated.
-
subscribeToForwardRequests: Get notified on requests to begin forward flows and interactively accept or reject or settle them.
-
subscribeToForwards: Get notified on off-chain routed payment events.
-
subscribeToGraph: Get notified of changes to the public routing graph nodes and channels.
-
subscribeToInvoice: Get notified of status updates for incoming payments.
-
subscribeToInvoices: Get notified of status updates on past created invoices.
-
subscribeToOpenRequests: Get notified on requests to open an inbound channel and interactively accept or reject them.
-
subscribeToPastPayment: Get notified of the current and ongoing status of a past off-chain payment.
-
subscribeToPayViaDetails: Make an off-chain payment using payment details and subscribe to the status of that payment.
-
subscribeToPayViaRequest: Make an off-chain payment using a payment request and subscribe to the payment status.
-
subscribeToPayViaRoutes: Start an off-chain payment using specific payment routes and subscribe to the payment result.
-
subscribeToProbeForRoute: Start an off-chain probe to find a payable route and get notified on the status of the probe.
-
subscribeToTransactions: Get notified on on-chain transaction activity.
-
subscribeToWalletStatus: Listen to updates to wallet state
-
unauthenticatedLndGrpc: Create an lnd object for use with methods that do not require authentication credentials.
-
unlockUtxo: Release a lease on a wallet UTXO to allow it to be selected for spending again.
-
unlockWallet: Decrypt the wallet and start the daemon
-
updateChainTransaction: Edit the metadata of an on-chain transaction record.
-
updateConnectedWatchtower: Edit the settings on an added watchtower
-
updatePathfindingSettings: Edit the configuration for routing calculations
-
updateRoutingFees: Set the forwarding fees or other routing policies for a channel or all channels.
-
verifyBackup: Check if a channel fund recovery backup file is valid.
-
verifyBackups: Check if multiple channel fund recovery backups are valid.
-
verifyBytesSignature: Check that a signature over arbitrary bytes is valid.
-
verifyMessage: Check that a message from a node in the graph has a valid signature.