LND gRPC API Reference
Welcome to the gRPC API reference documentation for LND, the Lightning Network
Daemon.
This site features the API documentation for lncli (CLI), Python,
and JavaScript in
order to communicate with a local lnd
instance through gRPC. It is intended
for those who already understand how to work with LND. If this is your first
time or you need a refresher, you may consider perusing our LND developer site
featuring a tutorial, resources and guides at dev.lightning.community.
The examples to the right 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.
At the time of writing this documentation, two things are needed in order to
make a gRPC request to an lnd
instance: a TLS/SSL connection and a macaroon
used for RPC authentication. The examples to the right will show how these can
be used in order to make a successful, secure, and authenticated gRPC request.
The original *.proto
files from which the gRPC documentation was generated
can be found here:
This is the reference for the gRPC API. Alternatively, there is also a REST
API which is documented here.
This documentation was
generated automatically against commit
17014b592e0fb0acb4b1ac6db9e298b8f9acc4f1
.
Experimental services
The following RPCs/services are currently considered to be experimental. This means
they are subject to change in the future. They also need to be enabled with a
compile-time flag to be active (they are active in the official release binaries).
Service Autopilot
ModifyStatus
Unary RPC
ModifyStatus is used to modify the status of the autopilot agent, like enabling or disabling it.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/autopilotrpc/autopilot.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import autopilot_pb2 as autopilotrpc, autopilot_pb2_grpc as autopilotstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = autopilotstub.AutopilotStub(channel)
>>> request = autopilotrpc.ModifyStatusRequest(
enable=<bool>,
)
>>> response = stub.ModifyStatus(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'autopilotrpc/autopilot.proto'], loaderOptions);
const autopilotrpc = grpc.loadPackageDefinition(packageDefinition).autopilotrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let autopilot = new autopilotrpc.Autopilot('localhost:10009', creds);
let request = {
enable: <bool>,
};
autopilot.modifyStatus(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
enable |
bool |
Whether the autopilot agent should be enabled or not. |
This response has no parameters.
QueryScores
Unary RPC
QueryScores queries all available autopilot heuristics, in addition to any active combination of these heruristics, for the scores they would give to the given nodes.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/autopilotrpc/autopilot.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import autopilot_pb2 as autopilotrpc, autopilot_pb2_grpc as autopilotstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = autopilotstub.AutopilotStub(channel)
>>> request = autopilotrpc.QueryScoresRequest(
pubkeys=<array string>,
ignore_local_state=<bool>,
)
>>> response = stub.QueryScores(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"results": <array HeuristicResult>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'autopilotrpc/autopilot.proto'], loaderOptions);
const autopilotrpc = grpc.loadPackageDefinition(packageDefinition).autopilotrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let autopilot = new autopilotrpc.Autopilot('localhost:10009', creds);
let request = {
pubkeys: <array string>,
ignore_local_state: <bool>,
};
autopilot.queryScores(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "results": <array HeuristicResult>,
// }
Parameter |
Type |
Description |
pubkeys |
array string |
|
ignore_local_state |
bool |
If set, we will ignore the local channel state when calculating scores. |
SetScores
Unary RPC
SetScores attempts to set the scores used by the running autopilot agent, if the external scoring heuristic is enabled.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/autopilotrpc/autopilot.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import autopilot_pb2 as autopilotrpc, autopilot_pb2_grpc as autopilotstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = autopilotstub.AutopilotStub(channel)
>>> request = autopilotrpc.SetScoresRequest(
heuristic=<string>,
scores=<array ScoresEntry>,
)
>>> response = stub.SetScores(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'autopilotrpc/autopilot.proto'], loaderOptions);
const autopilotrpc = grpc.loadPackageDefinition(packageDefinition).autopilotrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let autopilot = new autopilotrpc.Autopilot('localhost:10009', creds);
let request = {
heuristic: <string>,
scores: <array ScoresEntry>,
};
autopilot.setScores(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
heuristic |
string |
The name of the heuristic to provide scores to. |
scores |
array ScoresEntry |
A map from hex-encoded public keys to scores. Scores must be in the range [0.0, 1.0]. |
This response has no parameters.
Status
Unary RPC
Status returns whether the daemon's autopilot agent is active.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/autopilotrpc/autopilot.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import autopilot_pb2 as autopilotrpc, autopilot_pb2_grpc as autopilotstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = autopilotstub.AutopilotStub(channel)
>>> request = autopilotrpc.StatusRequest()
>>> response = stub.Status(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"active": <bool>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'autopilotrpc/autopilot.proto'], loaderOptions);
const autopilotrpc = grpc.loadPackageDefinition(packageDefinition).autopilotrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let autopilot = new autopilotrpc.Autopilot('localhost:10009', creds);
let request = {};
autopilot.status(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "active": <bool>,
// }
This request has no parameters.
Parameter |
Type |
Description |
active |
bool |
Indicates whether the autopilot is active or not. |
Service ChainNotifier
RegisterBlockEpochNtfn
Server-streaming RPC
RegisterBlockEpochNtfn is a synchronous response-streaming RPC that registers an intent for a client to be notified of blocks in the chain. The stream will return a hash and height tuple of a block for each new/stale block in the chain. It is the client's responsibility to determine whether the tuple returned is for a new or stale block in the chain. A client can also request a historical backlog of blocks from a particular point. This allows clients to be idempotent by ensuring that they do not missing processing a single block within the chain.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/chainrpc/chainnotifier.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import chainnotifier_pb2 as chainrpc, chainnotifier_pb2_grpc as chainnotifierstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = chainnotifierstub.ChainNotifierStub(channel)
>>> request = chainrpc.BlockEpoch(
hash=<bytes>,
height=<uint32>,
)
>>> for response in stub.RegisterBlockEpochNtfn(request, metadata=[('macaroon', macaroon)]):
print(response)
{
"hash": <bytes>,
"height": <uint32>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'chainrpc/chainnotifier.proto'], loaderOptions);
const chainrpc = grpc.loadPackageDefinition(packageDefinition).chainrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let chainNotifier = new chainrpc.ChainNotifier('localhost:10009', creds);
let request = {
hash: <bytes>,
height: <uint32>,
};
let call = chainNotifier.registerBlockEpochNtfn(request);
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
// Console output:
// {
// "hash": <bytes>,
// "height": <uint32>,
// }
Parameter |
Type |
Description |
hash |
bytes |
The hash of the block. |
height |
uint32 |
The height of the block. |
Parameter |
Type |
Description |
hash |
bytes |
The hash of the block. |
height |
uint32 |
The height of the block. |
RegisterConfirmationsNtfn
Server-streaming RPC
RegisterConfirmationsNtfn is a synchronous response-streaming RPC that registers an intent for a client to be notified once a confirmation request has reached its required number of confirmations on-chain. A confirmation request must have a valid output script. It is also possible to give a transaction ID. If the transaction ID is not set, a notification is sent once the output script confirms. If the transaction ID is also set, a notification is sent once the output script confirms in the given transaction.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/chainrpc/chainnotifier.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import chainnotifier_pb2 as chainrpc, chainnotifier_pb2_grpc as chainnotifierstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = chainnotifierstub.ChainNotifierStub(channel)
>>> request = chainrpc.ConfRequest(
txid=<bytes>,
script=<bytes>,
num_confs=<uint32>,
height_hint=<uint32>,
include_block=<bool>,
)
>>> for response in stub.RegisterConfirmationsNtfn(request, metadata=[('macaroon', macaroon)]):
print(response)
{
"conf": <ConfDetails>,
"reorg": <Reorg>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'chainrpc/chainnotifier.proto'], loaderOptions);
const chainrpc = grpc.loadPackageDefinition(packageDefinition).chainrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let chainNotifier = new chainrpc.ChainNotifier('localhost:10009', creds);
let request = {
txid: <bytes>,
script: <bytes>,
num_confs: <uint32>,
height_hint: <uint32>,
include_block: <bool>,
};
let call = chainNotifier.registerConfirmationsNtfn(request);
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
// Console output:
// {
// "conf": <ConfDetails>,
// "reorg": <Reorg>,
// }
Parameter |
Type |
Description |
txid |
bytes |
The transaction hash for which we should request a confirmation notification for. If set to a hash of all zeros, then the confirmation notification will be requested for the script instead. |
script |
bytes |
An output script within a transaction with the hash above which will be used by light clients to match block filters. If the transaction hash is set to a hash of all zeros, then a confirmation notification will be requested for this script instead. |
num_confs |
uint32 |
The number of desired confirmations the transaction/output script should reach before dispatching a confirmation notification. |
height_hint |
uint32 |
The earliest height in the chain for which the transaction/output script could have been included in a block. This should in most cases be set to the broadcast height of the transaction/output script. |
include_block |
bool |
If true, then the block that mines the specified txid/script will be included in eventual the notification event. |
Parameter |
Type |
Description |
conf |
ConfDetails |
An event that includes the confirmation details of the request (txid/ouput script). |
reorg |
Reorg |
An event send when the transaction of the request is reorged out of the chain. |
RegisterSpendNtfn
Server-streaming RPC
RegisterSpendNtfn is a synchronous response-streaming RPC that registers an intent for a client to be notification once a spend request has been spent by a transaction that has confirmed on-chain. A client can specify whether the spend request should be for a particular outpoint or for an output script by specifying a zero outpoint.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/chainrpc/chainnotifier.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import chainnotifier_pb2 as chainrpc, chainnotifier_pb2_grpc as chainnotifierstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = chainnotifierstub.ChainNotifierStub(channel)
>>> request = chainrpc.SpendRequest(
outpoint=<Outpoint>,
script=<bytes>,
height_hint=<uint32>,
)
>>> for response in stub.RegisterSpendNtfn(request, metadata=[('macaroon', macaroon)]):
print(response)
{
"spend": <SpendDetails>,
"reorg": <Reorg>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'chainrpc/chainnotifier.proto'], loaderOptions);
const chainrpc = grpc.loadPackageDefinition(packageDefinition).chainrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let chainNotifier = new chainrpc.ChainNotifier('localhost:10009', creds);
let request = {
outpoint: <Outpoint>,
script: <bytes>,
height_hint: <uint32>,
};
let call = chainNotifier.registerSpendNtfn(request);
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
// Console output:
// {
// "spend": <SpendDetails>,
// "reorg": <Reorg>,
// }
Parameter |
Type |
Description |
outpoint |
Outpoint |
The outpoint for which we should request a spend notification for. If set to a zero outpoint, then the spend notification will be requested for the script instead. A zero or nil outpoint is not supported for Taproot spends because the output script cannot reliably be computed from the witness alone and the spent output script is not always available in the rescan context. So an outpoint must always be specified when registering a spend notification for a Taproot output. |
script |
bytes |
The output script for the outpoint above. This will be used by light clients to match block filters. If the outpoint is set to a zero outpoint, then a spend notification will be requested for this script instead. |
height_hint |
uint32 |
The earliest height in the chain for which the outpoint/output script could have been spent. This should in most cases be set to the broadcast height of the outpoint/output script. |
Parameter |
Type |
Description |
spend |
SpendDetails |
An event that includes the details of the spending transaction of the request (outpoint/output script). |
reorg |
Reorg |
An event sent when the spending transaction of the request was reorged out of the chain. |
Service Dev
ImportGraph
Unary RPC
ImportGraph imports a ChannelGraph into the graph database. Should only be used for development.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/devrpc/dev.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import dev_pb2 as devrpc, dev_pb2_grpc as devstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = devstub.DevStub(channel)
>>> request = devrpc.ChannelGraph(
nodes=<array LightningNode>,
edges=<array ChannelEdge>,
)
>>> response = stub.ImportGraph(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'devrpc/dev.proto'], loaderOptions);
const devrpc = grpc.loadPackageDefinition(packageDefinition).devrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let dev = new devrpc.Dev('localhost:10009', creds);
let request = {
nodes: <array LightningNode>,
edges: <array ChannelEdge>,
};
dev.importGraph(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
This response has no parameters.
Service Invoices
AddHoldInvoice
Unary RPC
AddHoldInvoice creates a hold invoice. It ties the invoice to the hash supplied in the request.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/invoicesrpc/invoices.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import invoices_pb2 as invoicesrpc, invoices_pb2_grpc as invoicesstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = invoicesstub.InvoicesStub(channel)
>>> request = invoicesrpc.AddHoldInvoiceRequest(
memo=<string>,
hash=<bytes>,
value=<int64>,
value_msat=<int64>,
description_hash=<bytes>,
expiry=<int64>,
fallback_addr=<string>,
cltv_expiry=<uint64>,
route_hints=<array RouteHint>,
private=<bool>,
)
>>> response = stub.AddHoldInvoice(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"payment_request": <string>,
"add_index": <uint64>,
"payment_addr": <bytes>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'invoicesrpc/invoices.proto'], loaderOptions);
const invoicesrpc = grpc.loadPackageDefinition(packageDefinition).invoicesrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let invoices = new invoicesrpc.Invoices('localhost:10009', creds);
let request = {
memo: <string>,
hash: <bytes>,
value: <int64>,
value_msat: <int64>,
description_hash: <bytes>,
expiry: <int64>,
fallback_addr: <string>,
cltv_expiry: <uint64>,
route_hints: <array RouteHint>,
private: <bool>,
};
invoices.addHoldInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "payment_request": <string>,
// "add_index": <uint64>,
// "payment_addr": <bytes>,
// }
Parameter |
Type |
Description |
memo |
string |
An optional memo to attach along with the invoice. Used for record keeping purposes for the invoice's creator, and will also be set in the description field of the encoded payment request if the description_hash field is not being used. |
hash |
bytes |
The hash of the preimage |
value |
int64 |
The value of this invoice in satoshis The fields value and value_msat are mutually exclusive. |
value_msat |
int64 |
The value of this invoice in millisatoshis The fields value and value_msat are mutually exclusive. |
description_hash |
bytes |
Hash (SHA-256) of a description of the payment. Used if the description of payment (memo) is too long to naturally fit within the description field of an encoded payment request. |
expiry |
int64 |
Payment request expiry time in seconds. Default is 3600 (1 hour). |
fallback_addr |
string |
Fallback on-chain address. |
cltv_expiry |
uint64 |
Delta to use for the time-lock of the CLTV extended to the final hop. |
route_hints |
array RouteHint |
Route hints that can each be individually used to assist in reaching the invoice's destination. |
private |
bool |
Whether this invoice should include routing hints for private channels. |
Parameter |
Type |
Description |
payment_request |
string |
A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient. |
add_index |
uint64 |
The "add" index of this invoice. Each newly created invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all added invoices with an add_index greater than this one. |
payment_addr |
bytes |
The payment address of the generated invoice. This value should be used in all payments for this invoice as we require it for end to end security. |
CancelInvoice
Unary RPC
CancelInvoice cancels a currently open invoice. If the invoice is already canceled, this call will succeed. If the invoice is already settled, it will fail.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/invoicesrpc/invoices.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import invoices_pb2 as invoicesrpc, invoices_pb2_grpc as invoicesstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = invoicesstub.InvoicesStub(channel)
>>> request = invoicesrpc.CancelInvoiceMsg(
payment_hash=<bytes>,
)
>>> response = stub.CancelInvoice(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'invoicesrpc/invoices.proto'], loaderOptions);
const invoicesrpc = grpc.loadPackageDefinition(packageDefinition).invoicesrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let invoices = new invoicesrpc.Invoices('localhost:10009', creds);
let request = {
payment_hash: <bytes>,
};
invoices.cancelInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
payment_hash |
bytes |
Hash corresponding to the (hold) invoice to cancel. When using REST, this field must be encoded as base64. |
This response has no parameters.
LookupInvoiceV2
Unary RPC
LookupInvoiceV2 attempts to look up at invoice. An invoice can be refrenced using either its payment hash, payment address, or set ID.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/invoicesrpc/invoices.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import invoices_pb2 as invoicesrpc, invoices_pb2_grpc as invoicesstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = invoicesstub.InvoicesStub(channel)
>>> request = invoicesrpc.LookupInvoiceMsg(
payment_hash=<bytes>,
payment_addr=<bytes>,
set_id=<bytes>,
lookup_modifier=<LookupModifier>,
)
>>> response = stub.LookupInvoiceV2(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"memo": <string>,
"r_preimage": <bytes>,
"r_hash": <bytes>,
"value": <int64>,
"value_msat": <int64>,
"settled": <bool>,
"creation_date": <int64>,
"settle_date": <int64>,
"payment_request": <string>,
"description_hash": <bytes>,
"expiry": <int64>,
"fallback_addr": <string>,
"cltv_expiry": <uint64>,
"route_hints": <array RouteHint>,
"private": <bool>,
"add_index": <uint64>,
"settle_index": <uint64>,
"amt_paid": <int64>,
"amt_paid_sat": <int64>,
"amt_paid_msat": <int64>,
"state": <InvoiceState>,
"htlcs": <array InvoiceHTLC>,
"features": <array FeaturesEntry>,
"is_keysend": <bool>,
"payment_addr": <bytes>,
"is_amp": <bool>,
"amp_invoice_state": <array AmpInvoiceStateEntry>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'invoicesrpc/invoices.proto'], loaderOptions);
const invoicesrpc = grpc.loadPackageDefinition(packageDefinition).invoicesrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let invoices = new invoicesrpc.Invoices('localhost:10009', creds);
let request = {
payment_hash: <bytes>,
payment_addr: <bytes>,
set_id: <bytes>,
lookup_modifier: <LookupModifier>,
};
invoices.lookupInvoiceV2(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "memo": <string>,
// "r_preimage": <bytes>,
// "r_hash": <bytes>,
// "value": <int64>,
// "value_msat": <int64>,
// "settled": <bool>,
// "creation_date": <int64>,
// "settle_date": <int64>,
// "payment_request": <string>,
// "description_hash": <bytes>,
// "expiry": <int64>,
// "fallback_addr": <string>,
// "cltv_expiry": <uint64>,
// "route_hints": <array RouteHint>,
// "private": <bool>,
// "add_index": <uint64>,
// "settle_index": <uint64>,
// "amt_paid": <int64>,
// "amt_paid_sat": <int64>,
// "amt_paid_msat": <int64>,
// "state": <InvoiceState>,
// "htlcs": <array InvoiceHTLC>,
// "features": <array FeaturesEntry>,
// "is_keysend": <bool>,
// "payment_addr": <bytes>,
// "is_amp": <bool>,
// "amp_invoice_state": <array AmpInvoiceStateEntry>,
// }
Parameter |
Type |
Description |
payment_hash |
bytes |
When using REST, this field must be encoded as base64. |
payment_addr |
bytes |
|
set_id |
bytes |
|
lookup_modifier |
LookupModifier |
|
Parameter |
Type |
Description |
memo |
string |
An optional memo to attach along with the invoice. Used for record keeping purposes for the invoice's creator, and will also be set in the description field of the encoded payment request if the description_hash field is not being used. |
r_preimage |
bytes |
The hex-encoded preimage (32 byte) which will allow settling an incoming HTLC payable to this preimage. When using REST, this field must be encoded as base64. |
r_hash |
bytes |
The hash of the preimage. When using REST, this field must be encoded as base64. Note: Output only, don't specify for creating an invoice. |
value |
int64 |
The value of this invoice in satoshis The fields value and value_msat are mutually exclusive. |
value_msat |
int64 |
The value of this invoice in millisatoshis The fields value and value_msat are mutually exclusive. |
settled |
bool |
Whether this invoice has been fulfilled The field is deprecated. Use the state field instead (compare to SETTLED). |
creation_date |
int64 |
When this invoice was created. Note: Output only, don't specify for creating an invoice. |
settle_date |
int64 |
When this invoice was settled. Note: Output only, don't specify for creating an invoice. |
payment_request |
string |
A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient. Note: Output only, don't specify for creating an invoice. |
description_hash |
bytes |
Hash (SHA-256) of a description of the payment. Used if the description of payment (memo) is too long to naturally fit within the description field of an encoded payment request. When using REST, this field must be encoded as base64. |
expiry |
int64 |
Payment request expiry time in seconds. Default is 3600 (1 hour). |
fallback_addr |
string |
Fallback on-chain address. |
cltv_expiry |
uint64 |
Delta to use for the time-lock of the CLTV extended to the final hop. |
route_hints |
array RouteHint |
Route hints that can each be individually used to assist in reaching the invoice's destination. |
private |
bool |
Whether this invoice should include routing hints for private channels. |
add_index |
uint64 |
The "add" index of this invoice. Each newly created invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all added invoices with an add_index greater than this one. Note: Output only, don't specify for creating an invoice. |
settle_index |
uint64 |
The "settle" index of this invoice. Each newly settled invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all settled invoices with an settle_index greater than this one. Note: Output only, don't specify for creating an invoice. |
amt_paid |
int64 |
Deprecated, use amt_paid_sat or amt_paid_msat. |
amt_paid_sat |
int64 |
The amount that was accepted for this invoice, in satoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it's possible that the sender paid MORE that was specified in the original invoice. So we'll record that here as well. Note: Output only, don't specify for creating an invoice. |
amt_paid_msat |
int64 |
The amount that was accepted for this invoice, in millisatoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it's possible that the sender paid MORE that was specified in the original invoice. So we'll record that here as well. Note: Output only, don't specify for creating an invoice. |
state |
InvoiceState |
The state the invoice is in. Note: Output only, don't specify for creating an invoice. |
htlcs |
array InvoiceHTLC |
List of HTLCs paying to this invoice [EXPERIMENTAL]. Note: Output only, don't specify for creating an invoice. |
features |
array FeaturesEntry |
List of features advertised on the invoice. Note: Output only, don't specify for creating an invoice. |
is_keysend |
bool |
Indicates if this invoice was a spontaneous payment that arrived via keysend [EXPERIMENTAL]. Note: Output only, don't specify for creating an invoice. |
payment_addr |
bytes |
The payment address of this invoice. This value will be used in MPP payments, and also for newer invoices that always require the MPP payload for added end-to-end security. Note: Output only, don't specify for creating an invoice. |
is_amp |
bool |
Signals whether or not this is an AMP invoice. |
amp_invoice_state |
array AmpInvoiceStateEntry |
[EXPERIMENTAL]: Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the given set ID. This field is always populated for AMP invoices, and can be used along side LookupInvoice to obtain the HTLC information related to a given sub-invoice. Note: Output only, don't specify for creating an invoice. |
SettleInvoice
Unary RPC
SettleInvoice settles an accepted invoice. If the invoice is already settled, this call will succeed.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/invoicesrpc/invoices.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import invoices_pb2 as invoicesrpc, invoices_pb2_grpc as invoicesstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = invoicesstub.InvoicesStub(channel)
>>> request = invoicesrpc.SettleInvoiceMsg(
preimage=<bytes>,
)
>>> response = stub.SettleInvoice(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'invoicesrpc/invoices.proto'], loaderOptions);
const invoicesrpc = grpc.loadPackageDefinition(packageDefinition).invoicesrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let invoices = new invoicesrpc.Invoices('localhost:10009', creds);
let request = {
preimage: <bytes>,
};
invoices.settleInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
preimage |
bytes |
Externally discovered pre-image that should be used to settle the hold invoice. |
This response has no parameters.
SubscribeSingleInvoice
Server-streaming RPC
SubscribeSingleInvoice returns a uni-directional stream (server -> client) to notify the client of state transitions of the specified invoice. Initially the current invoice state is always sent out.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/invoicesrpc/invoices.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import invoices_pb2 as invoicesrpc, invoices_pb2_grpc as invoicesstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = invoicesstub.InvoicesStub(channel)
>>> request = invoicesrpc.SubscribeSingleInvoiceRequest(
r_hash=<bytes>,
)
>>> for response in stub.SubscribeSingleInvoice(request, metadata=[('macaroon', macaroon)]):
print(response)
{
"memo": <string>,
"r_preimage": <bytes>,
"r_hash": <bytes>,
"value": <int64>,
"value_msat": <int64>,
"settled": <bool>,
"creation_date": <int64>,
"settle_date": <int64>,
"payment_request": <string>,
"description_hash": <bytes>,
"expiry": <int64>,
"fallback_addr": <string>,
"cltv_expiry": <uint64>,
"route_hints": <array RouteHint>,
"private": <bool>,
"add_index": <uint64>,
"settle_index": <uint64>,
"amt_paid": <int64>,
"amt_paid_sat": <int64>,
"amt_paid_msat": <int64>,
"state": <InvoiceState>,
"htlcs": <array InvoiceHTLC>,
"features": <array FeaturesEntry>,
"is_keysend": <bool>,
"payment_addr": <bytes>,
"is_amp": <bool>,
"amp_invoice_state": <array AmpInvoiceStateEntry>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'invoicesrpc/invoices.proto'], loaderOptions);
const invoicesrpc = grpc.loadPackageDefinition(packageDefinition).invoicesrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let invoices = new invoicesrpc.Invoices('localhost:10009', creds);
let request = {
r_hash: <bytes>,
};
let call = invoices.subscribeSingleInvoice(request);
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
// Console output:
// {
// "memo": <string>,
// "r_preimage": <bytes>,
// "r_hash": <bytes>,
// "value": <int64>,
// "value_msat": <int64>,
// "settled": <bool>,
// "creation_date": <int64>,
// "settle_date": <int64>,
// "payment_request": <string>,
// "description_hash": <bytes>,
// "expiry": <int64>,
// "fallback_addr": <string>,
// "cltv_expiry": <uint64>,
// "route_hints": <array RouteHint>,
// "private": <bool>,
// "add_index": <uint64>,
// "settle_index": <uint64>,
// "amt_paid": <int64>,
// "amt_paid_sat": <int64>,
// "amt_paid_msat": <int64>,
// "state": <InvoiceState>,
// "htlcs": <array InvoiceHTLC>,
// "features": <array FeaturesEntry>,
// "is_keysend": <bool>,
// "payment_addr": <bytes>,
// "is_amp": <bool>,
// "amp_invoice_state": <array AmpInvoiceStateEntry>,
// }
Parameter |
Type |
Description |
r_hash |
bytes |
Hash corresponding to the (hold) invoice to subscribe to. When using REST, this field must be encoded as base64url. |
Parameter |
Type |
Description |
memo |
string |
An optional memo to attach along with the invoice. Used for record keeping purposes for the invoice's creator, and will also be set in the description field of the encoded payment request if the description_hash field is not being used. |
r_preimage |
bytes |
The hex-encoded preimage (32 byte) which will allow settling an incoming HTLC payable to this preimage. When using REST, this field must be encoded as base64. |
r_hash |
bytes |
The hash of the preimage. When using REST, this field must be encoded as base64. Note: Output only, don't specify for creating an invoice. |
value |
int64 |
The value of this invoice in satoshis The fields value and value_msat are mutually exclusive. |
value_msat |
int64 |
The value of this invoice in millisatoshis The fields value and value_msat are mutually exclusive. |
settled |
bool |
Whether this invoice has been fulfilled The field is deprecated. Use the state field instead (compare to SETTLED). |
creation_date |
int64 |
When this invoice was created. Note: Output only, don't specify for creating an invoice. |
settle_date |
int64 |
When this invoice was settled. Note: Output only, don't specify for creating an invoice. |
payment_request |
string |
A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient. Note: Output only, don't specify for creating an invoice. |
description_hash |
bytes |
Hash (SHA-256) of a description of the payment. Used if the description of payment (memo) is too long to naturally fit within the description field of an encoded payment request. When using REST, this field must be encoded as base64. |
expiry |
int64 |
Payment request expiry time in seconds. Default is 3600 (1 hour). |
fallback_addr |
string |
Fallback on-chain address. |
cltv_expiry |
uint64 |
Delta to use for the time-lock of the CLTV extended to the final hop. |
route_hints |
array RouteHint |
Route hints that can each be individually used to assist in reaching the invoice's destination. |
private |
bool |
Whether this invoice should include routing hints for private channels. |
add_index |
uint64 |
The "add" index of this invoice. Each newly created invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all added invoices with an add_index greater than this one. Note: Output only, don't specify for creating an invoice. |
settle_index |
uint64 |
The "settle" index of this invoice. Each newly settled invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all settled invoices with an settle_index greater than this one. Note: Output only, don't specify for creating an invoice. |
amt_paid |
int64 |
Deprecated, use amt_paid_sat or amt_paid_msat. |
amt_paid_sat |
int64 |
The amount that was accepted for this invoice, in satoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it's possible that the sender paid MORE that was specified in the original invoice. So we'll record that here as well. Note: Output only, don't specify for creating an invoice. |
amt_paid_msat |
int64 |
The amount that was accepted for this invoice, in millisatoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it's possible that the sender paid MORE that was specified in the original invoice. So we'll record that here as well. Note: Output only, don't specify for creating an invoice. |
state |
InvoiceState |
The state the invoice is in. Note: Output only, don't specify for creating an invoice. |
htlcs |
array InvoiceHTLC |
List of HTLCs paying to this invoice [EXPERIMENTAL]. Note: Output only, don't specify for creating an invoice. |
features |
array FeaturesEntry |
List of features advertised on the invoice. Note: Output only, don't specify for creating an invoice. |
is_keysend |
bool |
Indicates if this invoice was a spontaneous payment that arrived via keysend [EXPERIMENTAL]. Note: Output only, don't specify for creating an invoice. |
payment_addr |
bytes |
The payment address of this invoice. This value will be used in MPP payments, and also for newer invoices that always require the MPP payload for added end-to-end security. Note: Output only, don't specify for creating an invoice. |
is_amp |
bool |
Signals whether or not this is an AMP invoice. |
amp_invoice_state |
array AmpInvoiceStateEntry |
[EXPERIMENTAL]: Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the given set ID. This field is always populated for AMP invoices, and can be used along side LookupInvoice to obtain the HTLC information related to a given sub-invoice. Note: Output only, don't specify for creating an invoice. |
Service Lightning
AbandonChannel
Unary RPC
AbandonChannel removes all channel state from the database except for a close summary. This method can be used to get rid of permanently unusable channels due to bugs fixed in newer versions of lnd. This method can also be used to remove externally funded channels where the funding transaction was never broadcast. Only available for non-externally funded channels in dev build.
# Removes all channel state from the database except for a close
# summary. This method can be used to get rid of permanently unusable
# channels due to bugs fixed in newer versions of lnd.
# Only available when lnd is built in debug mode. The flag
# --i_know_what_i_am_doing can be set to override the debug/dev mode
# requirement.
# To view which funding_txids/output_indexes can be used for this command,
# see the channel_point values within the listchannels command output.
# The format for a channel_point is 'funding_txid:output_index'.
$ lncli abandonchannel [command options] funding_txid [output_index]
# --funding_txid value the txid of the channel's funding transaction
# --output_index value the output index for the funding output of the funding transaction (default: 0)
# --chan_point value (optional) the channel point. If set, funding_txid and output_index flags and positional arguments will be ignored
# --i_know_what_i_am_doing override the requirement for lnd needing to be in dev/debug mode to use this command; when setting this the user attests that they know the danger of using this command on channels and that doing so can lead to loss of funds if the channel funding TX ever confirms (or was confirmed)
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.AbandonChannelRequest(
channel_point=<ChannelPoint>,
pending_funding_shim_only=<bool>,
i_know_what_i_am_doing=<bool>,
)
>>> response = stub.AbandonChannel(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
channel_point: <ChannelPoint>,
pending_funding_shim_only: <bool>,
i_know_what_i_am_doing: <bool>,
};
lightning.abandonChannel(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
channel_point |
ChannelPoint |
|
pending_funding_shim_only |
bool |
|
i_know_what_i_am_doing |
bool |
Override the requirement for being in dev mode by setting this to true and confirming the user knows what they are doing and this is a potential foot gun to lose funds if used on active channels. |
This response has no parameters.
AddInvoice
Unary RPC
AddInvoice attempts to add a new invoice to the invoice database. Any duplicated invoices are rejected, therefore all invoices must have a unique payment preimage.
# Add a new invoice, expressing intent for a future payment.
# Invoices without an amount can be created by not supplying any
# parameters or providing an amount of 0. These invoices allow the payee
# to specify the amount of satoshis they wish to send.
$ lncli addinvoice [command options] value preimage
# --memo value a description of the payment to attach along with the invoice (default="")
# --preimage value the hex-encoded preimage (32 byte) which will allow settling an incoming HTLC payable to this preimage. If not set, a random preimage will be created.
# --amt value the amt of satoshis in this invoice (default: 0)
# --amt_msat value the amt of millisatoshis in this invoice (default: 0)
# --description_hash value SHA-256 hash of the description of the payment. Used if the purpose of payment cannot naturally fit within the memo. If provided this will be used instead of the description(memo) field in the encoded invoice.
# --fallback_addr value fallback on-chain address that can be used in case the lightning payment fails
# --expiry value the invoice's expiry time in seconds. If not specified an expiry of 3600 seconds (1 hour) is implied. (default: 0)
# --private encode routing hints in the invoice with private channels in order to assist the payer in reaching you
# --amp creates an AMP invoice. If true, preimage should not be set.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.Invoice(
memo=<string>,
r_preimage=<bytes>,
r_hash=<bytes>,
value=<int64>,
value_msat=<int64>,
settled=<bool>,
creation_date=<int64>,
settle_date=<int64>,
payment_request=<string>,
description_hash=<bytes>,
expiry=<int64>,
fallback_addr=<string>,
cltv_expiry=<uint64>,
route_hints=<array RouteHint>,
private=<bool>,
add_index=<uint64>,
settle_index=<uint64>,
amt_paid=<int64>,
amt_paid_sat=<int64>,
amt_paid_msat=<int64>,
state=<InvoiceState>,
htlcs=<array InvoiceHTLC>,
features=<array FeaturesEntry>,
is_keysend=<bool>,
payment_addr=<bytes>,
is_amp=<bool>,
amp_invoice_state=<array AmpInvoiceStateEntry>,
)
>>> response = stub.AddInvoice(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"r_hash": <bytes>,
"payment_request": <string>,
"add_index": <uint64>,
"payment_addr": <bytes>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
memo: <string>,
r_preimage: <bytes>,
r_hash: <bytes>,
value: <int64>,
value_msat: <int64>,
settled: <bool>,
creation_date: <int64>,
settle_date: <int64>,
payment_request: <string>,
description_hash: <bytes>,
expiry: <int64>,
fallback_addr: <string>,
cltv_expiry: <uint64>,
route_hints: <array RouteHint>,
private: <bool>,
add_index: <uint64>,
settle_index: <uint64>,
amt_paid: <int64>,
amt_paid_sat: <int64>,
amt_paid_msat: <int64>,
state: <InvoiceState>,
htlcs: <array InvoiceHTLC>,
features: <array FeaturesEntry>,
is_keysend: <bool>,
payment_addr: <bytes>,
is_amp: <bool>,
amp_invoice_state: <array AmpInvoiceStateEntry>,
};
lightning.addInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "r_hash": <bytes>,
// "payment_request": <string>,
// "add_index": <uint64>,
// "payment_addr": <bytes>,
// }
Parameter |
Type |
Description |
memo |
string |
An optional memo to attach along with the invoice. Used for record keeping purposes for the invoice's creator, and will also be set in the description field of the encoded payment request if the description_hash field is not being used. |
r_preimage |
bytes |
The hex-encoded preimage (32 byte) which will allow settling an incoming HTLC payable to this preimage. When using REST, this field must be encoded as base64. |
r_hash |
bytes |
The hash of the preimage. When using REST, this field must be encoded as base64. Note: Output only, don't specify for creating an invoice. |
value |
int64 |
The value of this invoice in satoshis The fields value and value_msat are mutually exclusive. |
value_msat |
int64 |
The value of this invoice in millisatoshis The fields value and value_msat are mutually exclusive. |
settled |
bool |
Whether this invoice has been fulfilled The field is deprecated. Use the state field instead (compare to SETTLED). |
creation_date |
int64 |
When this invoice was created. Note: Output only, don't specify for creating an invoice. |
settle_date |
int64 |
When this invoice was settled. Note: Output only, don't specify for creating an invoice. |
payment_request |
string |
A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient. Note: Output only, don't specify for creating an invoice. |
description_hash |
bytes |
Hash (SHA-256) of a description of the payment. Used if the description of payment (memo) is too long to naturally fit within the description field of an encoded payment request. When using REST, this field must be encoded as base64. |
expiry |
int64 |
Payment request expiry time in seconds. Default is 3600 (1 hour). |
fallback_addr |
string |
Fallback on-chain address. |
cltv_expiry |
uint64 |
Delta to use for the time-lock of the CLTV extended to the final hop. |
route_hints |
array RouteHint |
Route hints that can each be individually used to assist in reaching the invoice's destination. |
private |
bool |
Whether this invoice should include routing hints for private channels. |
add_index |
uint64 |
The "add" index of this invoice. Each newly created invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all added invoices with an add_index greater than this one. Note: Output only, don't specify for creating an invoice. |
settle_index |
uint64 |
The "settle" index of this invoice. Each newly settled invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all settled invoices with an settle_index greater than this one. Note: Output only, don't specify for creating an invoice. |
amt_paid |
int64 |
Deprecated, use amt_paid_sat or amt_paid_msat. |
amt_paid_sat |
int64 |
The amount that was accepted for this invoice, in satoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it's possible that the sender paid MORE that was specified in the original invoice. So we'll record that here as well. Note: Output only, don't specify for creating an invoice. |
amt_paid_msat |
int64 |
The amount that was accepted for this invoice, in millisatoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it's possible that the sender paid MORE that was specified in the original invoice. So we'll record that here as well. Note: Output only, don't specify for creating an invoice. |
state |
InvoiceState |
The state the invoice is in. Note: Output only, don't specify for creating an invoice. |
htlcs |
array InvoiceHTLC |
List of HTLCs paying to this invoice [EXPERIMENTAL]. Note: Output only, don't specify for creating an invoice. |
features |
array FeaturesEntry |
List of features advertised on the invoice. Note: Output only, don't specify for creating an invoice. |
is_keysend |
bool |
Indicates if this invoice was a spontaneous payment that arrived via keysend [EXPERIMENTAL]. Note: Output only, don't specify for creating an invoice. |
payment_addr |
bytes |
The payment address of this invoice. This value will be used in MPP payments, and also for newer invoices that always require the MPP payload for added end-to-end security. Note: Output only, don't specify for creating an invoice. |
is_amp |
bool |
Signals whether or not this is an AMP invoice. |
amp_invoice_state |
array AmpInvoiceStateEntry |
[EXPERIMENTAL]: Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the given set ID. This field is always populated for AMP invoices, and can be used along side LookupInvoice to obtain the HTLC information related to a given sub-invoice. Note: Output only, don't specify for creating an invoice. |
Parameter |
Type |
Description |
r_hash |
bytes |
|
payment_request |
string |
A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient. |
add_index |
uint64 |
The "add" index of this invoice. Each newly created invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all added invoices with an add_index greater than this one. |
payment_addr |
bytes |
The payment address of the generated invoice. This value should be used in all payments for this invoice as we require it for end to end security. |
BakeMacaroon
Unary RPC
BakeMacaroon allows the creation of a new macaroon with custom read and write permissions. No first-party caveats are added since this can be done offline.
# Bake a new macaroon that grants the provided permissions and
# optionally adds restrictions (timeout, IP address) to it.
# The new macaroon can either be shown on command line in hex serialized
# format or it can be saved directly to a file using the --save_to
# argument.
# A permission is a tuple of an entity and an action, separated by a
# colon. Multiple operations can be added as arguments, for example:
# lncli bakemacaroon info:read invoices:write foo:bar
# For even more fine-grained permission control, it is also possible to
# specify single RPC method URIs that are allowed to be accessed by a
# macaroon. This can be achieved by specifying "uri:<methodURI>" pairs,
# for example:
# lncli bakemacaroon uri:/lnrpc.Lightning/GetInfo uri:/verrpc.Versioner/GetVersion
# The macaroon created by this command would only be allowed to use the
# "lncli getinfo" and "lncli version" commands.
# To get a list of all available URIs and permissions, use the
# "lncli listpermissions" command.
$ lncli bakemacaroon [command options] [--save_to=] [--timeout=] [--ip_address=] [--custom_caveat_name= [--custom_caveat_condition=]] [--root_key_id=] [--allow_external_permissions] permissions...
# --save_to value save the created macaroon to this file using the default binary format
# --timeout value the number of seconds the macaroon will be valid before it times out (default: 0)
# --ip_address value the IP address the macaroon will be bound to
# --custom_caveat_name value the name of the custom caveat to add
# --custom_caveat_condition value the condition of the custom caveat to add, can be empty if custom caveat doesn't need a value
# --root_key_id value the numerical root key ID used to create the macaroon (default: 0)
# --allow_external_permissions whether permissions lnd is not familiar with are allowed
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.BakeMacaroonRequest(
permissions=<array MacaroonPermission>,
root_key_id=<uint64>,
allow_external_permissions=<bool>,
)
>>> response = stub.BakeMacaroon(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"macaroon": <string>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
permissions: <array MacaroonPermission>,
root_key_id: <uint64>,
allow_external_permissions: <bool>,
};
lightning.bakeMacaroon(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "macaroon": <string>,
// }
Parameter |
Type |
Description |
permissions |
array MacaroonPermission |
The list of permissions the new macaroon should grant. |
root_key_id |
uint64 |
The root key ID used to create the macaroon, must be a positive integer. |
allow_external_permissions |
bool |
Informs the RPC on whether to allow external permissions that LND is not aware of. |
Parameter |
Type |
Description |
macaroon |
string |
The hex encoded macaroon, serialized in binary format. |
BatchOpenChannel
Unary RPC
BatchOpenChannel attempts to open multiple single-funded channels in a single transaction in an atomic way. This means either all channel open requests succeed at once or all attempts are aborted if any of them fail. This is the safer variant of using PSBTs to manually fund a batch of channels through the OpenChannel RPC.
# Attempt to open one or more new channels to an existing peer with the
# given node-keys.
# Example:
# lncli batchopenchannel --sat_per_vbyte=5 '[{
# "node_pubkey": "02abcdef...",
# "local_funding_amount": 500000,
# "private": true,
# "close_address": "bc1qxxx..."
# }, {
# "node_pubkey": "03fedcba...",
# "local_funding_amount": 200000,
# "remote_csv_delay": 288
# }]'
# All nodes listed must already be connected peers, otherwise funding will
# fail.
# The channel will be initialized with local_funding_amount satoshis
# locally and push_sat satoshis for the remote node. Note that specifying
# push_sat means you give that amount to the remote node as part of the
# channel opening. Once the channel is open, a channelPoint (txid:vout) of
# the funding output is returned.
# If the remote peer supports the option upfront shutdown feature bit
# (query listpeers to see their supported feature bits), an address to
# enforce payout of funds on cooperative close can optionally be provided.
# Note that if you set this value, you will not be able to cooperatively
# close out to another address.
# One can manually set the fee to be used for the funding transaction via
# either the --conf_target or --sat_per_vbyte arguments. This is optional.
$ lncli batchopenchannel [command options] channels-json
# --conf_target value (optional) the number of blocks that the transaction *should* confirm in, will be used for fee estimation (default: 0)
# --sat_per_vbyte value (optional) a manual fee expressed in sat/vByte that should be used when crafting the transaction (default: 0)
# --min_confs value (optional) the minimum number of confirmations each one of your outputs used for the funding transaction must satisfy (default: 1)
# --label value (optional) a label to attach to the batch transaction when storing it to the local wallet after publishing it
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.BatchOpenChannelRequest(
channels=<array BatchOpenChannel>,
target_conf=<int32>,
sat_per_vbyte=<int64>,
min_confs=<int32>,
spend_unconfirmed=<bool>,
label=<string>,
)
>>> response = stub.BatchOpenChannel(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"pending_channels": <array PendingUpdate>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
channels: <array BatchOpenChannel>,
target_conf: <int32>,
sat_per_vbyte: <int64>,
min_confs: <int32>,
spend_unconfirmed: <bool>,
label: <string>,
};
lightning.batchOpenChannel(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "pending_channels": <array PendingUpdate>,
// }
Parameter |
Type |
Description |
channels |
array BatchOpenChannel |
The list of channels to open. |
target_conf |
int32 |
The target number of blocks that the funding transaction should be confirmed by. |
sat_per_vbyte |
int64 |
A manual fee rate set in sat/vByte that should be used when crafting the funding transaction. |
min_confs |
int32 |
The minimum number of confirmations each one of your outputs used for the funding transaction must satisfy. |
spend_unconfirmed |
bool |
Whether unconfirmed outputs should be used as inputs for the funding transaction. |
label |
string |
An optional label for the batch transaction, limited to 500 characters. |
ChannelAcceptor
Bidirectional-streaming RPC
ChannelAcceptor dispatches a bi-directional streaming RPC in which OpenChannel requests are sent to the client and the client responds with a boolean that tells LND whether or not to accept the channel. This allows node operators to specify their own criteria for accepting inbound channels through a single persistent connection.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
# Define a generator that returns an Iterable of lnrpc.ChannelAcceptResponse objects.
>>> def request_generator():
# Initialization code here.
while True:
# Parameters here can be set as arguments to the generator.
request = lnrpc.ChannelAcceptResponse(
accept=<bool>,
pending_chan_id=<bytes>,
error=<string>,
upfront_shutdown=<string>,
csv_delay=<uint32>,
reserve_sat=<uint64>,
in_flight_max_msat=<uint64>,
max_htlc_count=<uint32>,
min_htlc_in=<uint64>,
min_accept_depth=<uint32>,
zero_conf=<bool>,
)
yield request
# Do things between iterations here.
>>> request_iterable = request_generator()
>>> for response in stub.ChannelAcceptor(request_iterable, metadata=[('macaroon', macaroon)]):
print(response)
{
"node_pubkey": <bytes>,
"chain_hash": <bytes>,
"pending_chan_id": <bytes>,
"funding_amt": <uint64>,
"push_amt": <uint64>,
"dust_limit": <uint64>,
"max_value_in_flight": <uint64>,
"channel_reserve": <uint64>,
"min_htlc": <uint64>,
"fee_per_kw": <uint64>,
"csv_delay": <uint32>,
"max_accepted_htlcs": <uint32>,
"channel_flags": <uint32>,
"commitment_type": <CommitmentType>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
accept: <bool>,
pending_chan_id: <bytes>,
error: <string>,
upfront_shutdown: <string>,
csv_delay: <uint32>,
reserve_sat: <uint64>,
in_flight_max_msat: <uint64>,
max_htlc_count: <uint32>,
min_htlc_in: <uint64>,
min_accept_depth: <uint32>,
zero_conf: <bool>,
};
let call = lightning.channelAcceptor({});
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
call.write(request);
// Console output:
// {
// "node_pubkey": <bytes>,
// "chain_hash": <bytes>,
// "pending_chan_id": <bytes>,
// "funding_amt": <uint64>,
// "push_amt": <uint64>,
// "dust_limit": <uint64>,
// "max_value_in_flight": <uint64>,
// "channel_reserve": <uint64>,
// "min_htlc": <uint64>,
// "fee_per_kw": <uint64>,
// "csv_delay": <uint32>,
// "max_accepted_htlcs": <uint32>,
// "channel_flags": <uint32>,
// "commitment_type": <CommitmentType>,
// }
Parameter |
Type |
Description |
accept |
bool |
Whether or not the client accepts the channel. |
pending_chan_id |
bytes |
The pending channel id to which this response applies. |
error |
string |
An optional error to send the initiating party to indicate why the channel was rejected. This field should not contain sensitive information, it will be sent to the initiating party. This field should only be set if accept is false, the channel will be rejected if an error is set with accept=true because the meaning of this response is ambiguous. Limited to 500 characters. |
upfront_shutdown |
string |
The upfront shutdown address to use if the initiating peer supports option upfront shutdown script (see ListPeers for the features supported). Note that the channel open will fail if this value is set for a peer that does not support this feature bit. |
csv_delay |
uint32 |
The csv delay (in blocks) that we require for the remote party. |
reserve_sat |
uint64 |
The reserve amount in satoshis that we require the remote peer to adhere to. We require that the remote peer always have some reserve amount allocated to them so that there is always a disincentive to broadcast old state (if they hold 0 sats on their side of the channel, there is nothing to lose). |
in_flight_max_msat |
uint64 |
The maximum amount of funds in millisatoshis that we allow the remote peer to have in outstanding htlcs. |
max_htlc_count |
uint32 |
The maximum number of htlcs that the remote peer can offer us. |
min_htlc_in |
uint64 |
The minimum value in millisatoshis for incoming htlcs on the channel. |
min_accept_depth |
uint32 |
The number of confirmations we require before we consider the channel open. |
zero_conf |
bool |
Whether the responder wants this to be a zero-conf channel. This will fail if either side does not have the scid-alias feature bit set. The minimum depth field must be zero if this is true. |
Parameter |
Type |
Description |
node_pubkey |
bytes |
The pubkey of the node that wishes to open an inbound channel. |
chain_hash |
bytes |
The hash of the genesis block that the proposed channel resides in. |
pending_chan_id |
bytes |
The pending channel id. |
funding_amt |
uint64 |
The funding amount in satoshis that initiator wishes to use in the channel. |
push_amt |
uint64 |
The push amount of the proposed channel in millisatoshis. |
dust_limit |
uint64 |
The dust limit of the initiator's commitment tx. |
max_value_in_flight |
uint64 |
The maximum amount of coins in millisatoshis that can be pending in this channel. |
channel_reserve |
uint64 |
The minimum amount of satoshis the initiator requires us to have at all times. |
min_htlc |
uint64 |
The smallest HTLC in millisatoshis that the initiator will accept. |
fee_per_kw |
uint64 |
The initial fee rate that the initiator suggests for both commitment transactions. |
csv_delay |
uint32 |
The number of blocks to use for the relative time lock in the pay-to-self output of both commitment transactions. |
max_accepted_htlcs |
uint32 |
The total number of incoming HTLC's that the initiator will accept. |
channel_flags |
uint32 |
A bit-field which the initiator uses to specify proposed channel behavior. |
commitment_type |
CommitmentType |
The commitment type the initiator wishes to use for the proposed channel. |
ChannelBalance
Unary RPC
ChannelBalance returns a report on the total funds across all open channels, categorized in local/remote, pending local/remote and unsettled local/remote balances.
# Returns the sum of the total available channel balance across all open channels.
$ lncli channelbalance [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ChannelBalanceRequest()
>>> response = stub.ChannelBalance(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"balance": <int64>,
"pending_open_balance": <int64>,
"local_balance": <Amount>,
"remote_balance": <Amount>,
"unsettled_local_balance": <Amount>,
"unsettled_remote_balance": <Amount>,
"pending_open_local_balance": <Amount>,
"pending_open_remote_balance": <Amount>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.channelBalance(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "balance": <int64>,
// "pending_open_balance": <int64>,
// "local_balance": <Amount>,
// "remote_balance": <Amount>,
// "unsettled_local_balance": <Amount>,
// "unsettled_remote_balance": <Amount>,
// "pending_open_local_balance": <Amount>,
// "pending_open_remote_balance": <Amount>,
// }
This request has no parameters.
Parameter |
Type |
Description |
balance |
int64 |
Deprecated. Sum of channels balances denominated in satoshis |
pending_open_balance |
int64 |
Deprecated. Sum of channels pending balances denominated in satoshis |
local_balance |
Amount |
Sum of channels local balances. |
remote_balance |
Amount |
Sum of channels remote balances. |
unsettled_local_balance |
Amount |
Sum of channels local unsettled balances. |
unsettled_remote_balance |
Amount |
Sum of channels remote unsettled balances. |
pending_open_local_balance |
Amount |
Sum of channels pending local balances. |
pending_open_remote_balance |
Amount |
Sum of channels pending remote balances. |
CheckMacaroonPermissions
Unary RPC
CheckMacaroonPermissions checks whether a request follows the constraints imposed on the macaroon and that the macaroon is authorized to follow the provided permissions.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.CheckMacPermRequest(
macaroon=<bytes>,
permissions=<array MacaroonPermission>,
fullMethod=<string>,
)
>>> response = stub.CheckMacaroonPermissions(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"valid": <bool>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
macaroon: <bytes>,
permissions: <array MacaroonPermission>,
fullMethod: <string>,
};
lightning.checkMacaroonPermissions(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "valid": <bool>,
// }
Parameter |
Type |
Description |
valid |
bool |
|
CloseChannel
Server-streaming RPC
CloseChannel attempts to close an active channel identified by its channel outpoint (ChannelPoint). The actions of this method can additionally be augmented to attempt a force close after a timeout period in the case of an inactive peer. If a non-force close (cooperative closure) is requested, then the user can specify either a target number of blocks until the closure transaction is confirmed, or a manual fee rate. If neither are specified, then a default lax, block confirmation target is used.
# Close an existing channel. The channel can be closed either cooperatively,
# or unilaterally (--force).
# A unilateral channel closure means that the latest commitment
# transaction will be broadcast to the network. As a result, any settled
# funds will be time locked for a few blocks before they can be spent.
# In the case of a cooperative closure, one can manually set the fee to
# be used for the closing transaction via either the --conf_target or
# --sat_per_vbyte arguments. This will be the starting value used during
# fee negotiation. This is optional.
# In the case of a cooperative closure, one can manually set the address
# to deliver funds to upon closure. This is optional, and may only be used
# if an upfront shutdown address has not already been set. If neither are
# set the funds will be delivered to a new wallet address.
# To view which funding_txids/output_indexes can be used for a channel close,
# see the channel_point values within the listchannels command output.
# The format for a channel_point is 'funding_txid:output_index'.
$ lncli closechannel [command options] funding_txid [output_index]
# --funding_txid value the txid of the channel's funding transaction
# --output_index value the output index for the funding output of the funding transaction (default: 0)
# --chan_point value (optional) the channel point. If set, funding_txid and output_index flags and positional arguments will be ignored
# --force attempt an uncooperative closure
# --block block until the channel is closed
# --conf_target value (optional) the number of blocks that the transaction *should* confirm in, will be used for fee estimation. If not set, then the conf-target value set in the main lnd config will be used. (default: 0)
# --sat_per_vbyte value (optional) a manual fee expressed in sat/vbyte that should be used when crafting the transaction (default: 0)
# --delivery_addr value (optional) an address to deliver funds upon cooperative channel closing, may only be used if an upfront shutdown address is not already set
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.CloseChannelRequest(
channel_point=<ChannelPoint>,
force=<bool>,
target_conf=<int32>,
sat_per_byte=<int64>,
delivery_address=<string>,
sat_per_vbyte=<uint64>,
max_fee_per_vbyte=<uint64>,
)
>>> for response in stub.CloseChannel(request, metadata=[('macaroon', macaroon)]):
print(response)
{
"close_pending": <PendingUpdate>,
"chan_close": <ChannelCloseUpdate>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
channel_point: <ChannelPoint>,
force: <bool>,
target_conf: <int32>,
sat_per_byte: <int64>,
delivery_address: <string>,
sat_per_vbyte: <uint64>,
max_fee_per_vbyte: <uint64>,
};
let call = lightning.closeChannel(request);
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
// Console output:
// {
// "close_pending": <PendingUpdate>,
// "chan_close": <ChannelCloseUpdate>,
// }
Parameter |
Type |
Description |
channel_point |
ChannelPoint |
The outpoint (txid:index) of the funding transaction. With this value, Bob will be able to generate a signature for Alice's version of the commitment transaction. |
force |
bool |
If true, then the channel will be closed forcibly. This means the current commitment transaction will be signed and broadcast. |
target_conf |
int32 |
The target number of blocks that the closure transaction should be confirmed by. |
sat_per_byte |
int64 |
Deprecated, use sat_per_vbyte. A manual fee rate set in sat/vbyte that should be used when crafting the closure transaction. |
delivery_address |
string |
An optional address to send funds to in the case of a cooperative close. If the channel was opened with an upfront shutdown script and this field is set, the request to close will fail because the channel must pay out to the upfront shutdown addresss. |
sat_per_vbyte |
uint64 |
A manual fee rate set in sat/vbyte that should be used when crafting the closure transaction. |
max_fee_per_vbyte |
uint64 |
The maximum fee rate the closer is willing to pay. NOTE: This field is only respected if we're the initiator of the channel. |
ClosedChannels
Unary RPC
ClosedChannels returns a description of all the closed channels that this node was a participant in.
# List all closed channels.
$ lncli closedchannels [command options] [arguments...]
# --cooperative list channels that were closed cooperatively
# --local_force list channels that were force-closed by the local node
# --remote_force list channels that were force-closed by the remote node
# --breach list channels for which the remote node attempted to broadcast a prior revoked channel state
# --funding_canceled list channels that were never fully opened
# --abandoned list channels that were abandoned by the local node
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ClosedChannelsRequest(
cooperative=<bool>,
local_force=<bool>,
remote_force=<bool>,
breach=<bool>,
funding_canceled=<bool>,
abandoned=<bool>,
)
>>> response = stub.ClosedChannels(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"channels": <array ChannelCloseSummary>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
cooperative: <bool>,
local_force: <bool>,
remote_force: <bool>,
breach: <bool>,
funding_canceled: <bool>,
abandoned: <bool>,
};
lightning.closedChannels(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "channels": <array ChannelCloseSummary>,
// }
Parameter |
Type |
Description |
cooperative |
bool |
|
local_force |
bool |
|
remote_force |
bool |
|
breach |
bool |
|
funding_canceled |
bool |
|
abandoned |
bool |
|
ConnectPeer
Unary RPC
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.
# Connect to a peer using its <pubkey> and host.
# A custom timeout on the connection is supported. For instance, to timeout
# the connection request in 30 seconds, use the following:
# lncli connect <pubkey>@host --timeout 30s
$ lncli connect [command options] <pubkey>@host
# --perm If set, the daemon will attempt to persistently connect to the target peer.
# If not, the call will be synchronous.
# --timeout value The connection timeout value for current request. Valid uints are {ms, s, m, h}.
# If not set, the global connection timeout value (default to 120s) is used. (default: 0s)
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ConnectPeerRequest(
addr=<LightningAddress>,
perm=<bool>,
timeout=<uint64>,
)
>>> response = stub.ConnectPeer(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
addr: <LightningAddress>,
perm: <bool>,
timeout: <uint64>,
};
lightning.connectPeer(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
addr |
LightningAddress |
Lightning address of the peer to connect to. |
perm |
bool |
If set, the daemon will attempt to persistently connect to the target peer. Otherwise, the call will be synchronous. |
timeout |
uint64 |
The connection timeout value (in seconds) for this request. It won't affect other requests. |
This response has no parameters.
DebugLevel
Unary RPC
DebugLevel allows a caller to programmatically set the logging verbosity of lnd. The logging can be targeted according to a coarse daemon-wide logging level, or in a granular fashion to specify the logging for a target sub-system.
# Logging level for all subsystems {trace, debug, info, warn, error, critical, off}
# You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems
# Use show to list available subsystems
$ lncli debuglevel [command options] [arguments...]
# --show if true, then the list of available sub-systems will be printed out
# --level value the level specification to target either a coarse logging level, or granular set of specific sub-systems with logging levels for each
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.DebugLevelRequest(
show=<bool>,
level_spec=<string>,
)
>>> response = stub.DebugLevel(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"sub_systems": <string>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
show: <bool>,
level_spec: <string>,
};
lightning.debugLevel(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "sub_systems": <string>,
// }
Parameter |
Type |
Description |
show |
bool |
|
level_spec |
string |
|
Parameter |
Type |
Description |
sub_systems |
string |
|
DecodePayReq
Unary RPC
DecodePayReq takes an encoded payment request string and attempts to decode it, returning a full description of the conditions encoded within the payment request.
# Decode the passed payment request revealing the destination, payment hash and value of the payment request
$ lncli decodepayreq [command options] pay_req
# --pay_req value the bech32 encoded payment request
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.PayReqString(
pay_req=<string>,
)
>>> response = stub.DecodePayReq(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"destination": <string>,
"payment_hash": <string>,
"num_satoshis": <int64>,
"timestamp": <int64>,
"expiry": <int64>,
"description": <string>,
"description_hash": <string>,
"fallback_addr": <string>,
"cltv_expiry": <int64>,
"route_hints": <array RouteHint>,
"payment_addr": <bytes>,
"num_msat": <int64>,
"features": <array FeaturesEntry>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
pay_req: <string>,
};
lightning.decodePayReq(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "destination": <string>,
// "payment_hash": <string>,
// "num_satoshis": <int64>,
// "timestamp": <int64>,
// "expiry": <int64>,
// "description": <string>,
// "description_hash": <string>,
// "fallback_addr": <string>,
// "cltv_expiry": <int64>,
// "route_hints": <array RouteHint>,
// "payment_addr": <bytes>,
// "num_msat": <int64>,
// "features": <array FeaturesEntry>,
// }
Parameter |
Type |
Description |
pay_req |
string |
The payment request string to be decoded |
Parameter |
Type |
Description |
destination |
string |
|
payment_hash |
string |
|
num_satoshis |
int64 |
|
timestamp |
int64 |
|
expiry |
int64 |
|
description |
string |
|
description_hash |
string |
|
fallback_addr |
string |
|
cltv_expiry |
int64 |
|
route_hints |
array RouteHint |
|
payment_addr |
bytes |
|
num_msat |
int64 |
|
features |
array FeaturesEntry |
|
DeleteAllPayments
Unary RPC
DeleteAllPayments deletes all outgoing payments from DB. Note that it will not attempt to delete In-Flight payments, since that would be unsafe.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.DeleteAllPaymentsRequest(
failed_payments_only=<bool>,
failed_htlcs_only=<bool>,
)
>>> response = stub.DeleteAllPayments(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
failed_payments_only: <bool>,
failed_htlcs_only: <bool>,
};
lightning.deleteAllPayments(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
failed_payments_only |
bool |
Only delete failed payments. |
failed_htlcs_only |
bool |
Only delete failed HTLCs from payments, not the payment itself. |
This response has no parameters.
DeleteMacaroonID
Unary RPC
DeleteMacaroonID deletes the specified macaroon ID and invalidates all macaroons derived from that ID.
# Remove a macaroon ID using the specified root key ID. For example:
# lncli deletemacaroonid 1
# WARNING
# When the ID is deleted, all macaroons created from that root key will
# be invalidated.
# Note that the default root key ID 0 cannot be deleted.
$ lncli deletemacaroonid root_key_id
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.DeleteMacaroonIDRequest(
root_key_id=<uint64>,
)
>>> response = stub.DeleteMacaroonID(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"deleted": <bool>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
root_key_id: <uint64>,
};
lightning.deleteMacaroonID(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "deleted": <bool>,
// }
Parameter |
Type |
Description |
root_key_id |
uint64 |
The root key ID to be removed. |
Parameter |
Type |
Description |
deleted |
bool |
A boolean indicates that the deletion is successful. |
DeletePayment
Unary RPC
DeletePayment deletes an outgoing payment from DB. Note that it will not attempt to delete an In-Flight payment, since that would be unsafe.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.DeletePaymentRequest(
payment_hash=<bytes>,
failed_htlcs_only=<bool>,
)
>>> response = stub.DeletePayment(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
payment_hash: <bytes>,
failed_htlcs_only: <bool>,
};
lightning.deletePayment(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
payment_hash |
bytes |
Payment hash to delete. |
failed_htlcs_only |
bool |
Only delete failed HTLCs from the payment, not the payment itself. |
This response has no parameters.
DescribeGraph
Unary RPC
DescribeGraph returns a description of the latest graph state from the point of view of the node. The graph information is partitioned into two components: all the nodes/vertexes, and all the edges that connect the vertexes themselves. As this is a directed graph, the edges also contain the node directional specific routing policy which includes: the time lock delta, fee information, etc.
# Prints a human readable version of the known channel graph from the PoV of the node
$ lncli describegraph [command options] [arguments...]
# --include_unannounced If set, unannounced channels will be included in the graph. Unannounced channels are both private channels, and public channels that are not yet announced to the network.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ChannelGraphRequest(
include_unannounced=<bool>,
)
>>> response = stub.DescribeGraph(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"nodes": <array LightningNode>,
"edges": <array ChannelEdge>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
include_unannounced: <bool>,
};
lightning.describeGraph(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "nodes": <array LightningNode>,
// "edges": <array ChannelEdge>,
// }
Parameter |
Type |
Description |
include_unannounced |
bool |
Whether unannounced channels are included in the response or not. If set, unannounced channels are included. Unannounced channels are both private channels, and public channels that are not yet announced to the network. |
DisconnectPeer
Unary RPC
DisconnectPeer attempts to disconnect one peer from another identified by a given pubKey. In the case that we currently have a pending or active channel with the target peer, then this action will be not be allowed.
# Disconnect a remote lnd peer identified by public key.
$ lncli disconnect [command options] <pubkey>
# --node_key value The hex-encoded compressed public key of the peer to disconnect from
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.DisconnectPeerRequest(
pub_key=<string>,
)
>>> response = stub.DisconnectPeer(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
pub_key: <string>,
};
lightning.disconnectPeer(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
pub_key |
string |
The pubkey of the node to disconnect from |
This response has no parameters.
EstimateFee
Unary RPC
EstimateFee asks the chain backend to estimate the fee rate and total fees for a transaction that pays to multiple specified outputs. When using REST, the AddrToAmount
map type can be set by appending &AddrToAmount[<address>]=<amount_to_send>
to the URL. Unfortunately this map type doesn't appear in the REST API documentation because of a bug in the grpc-gateway library.
# Get fee estimates for sending a transaction paying the specified amount(s) to the passed address(es).
# The send-json-string' param decodes addresses and the amount to send respectively in the following format:
# '{"ExampleAddr": NumCoinsInSatoshis, "SecondAddr": NumCoins}'
$ lncli estimatefee [command options] send-json-string [--conf_target=N]
# --conf_target value (optional) the number of blocks that the transaction *should* confirm in (default: 0)
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.EstimateFeeRequest(
AddrToAmount=<array AddrToAmountEntry>,
target_conf=<int32>,
min_confs=<int32>,
spend_unconfirmed=<bool>,
)
>>> response = stub.EstimateFee(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"fee_sat": <int64>,
"feerate_sat_per_byte": <int64>,
"sat_per_vbyte": <uint64>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
AddrToAmount: <array AddrToAmountEntry>,
target_conf: <int32>,
min_confs: <int32>,
spend_unconfirmed: <bool>,
};
lightning.estimateFee(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "fee_sat": <int64>,
// "feerate_sat_per_byte": <int64>,
// "sat_per_vbyte": <uint64>,
// }
Parameter |
Type |
Description |
AddrToAmount |
array AddrToAmountEntry |
The map from addresses to amounts for the transaction. |
target_conf |
int32 |
The target number of blocks that this transaction should be confirmed by. |
min_confs |
int32 |
The minimum number of confirmations each one of your outputs used for the transaction must satisfy. |
spend_unconfirmed |
bool |
Whether unconfirmed outputs should be used as inputs for the transaction. |
Parameter |
Type |
Description |
fee_sat |
int64 |
The total fee in satoshis. |
feerate_sat_per_byte |
int64 |
Deprecated, use sat_per_vbyte. The fee rate in satoshi/vbyte. |
sat_per_vbyte |
uint64 |
The fee rate in satoshi/vbyte. |
ExportAllChannelBackups
Unary RPC
ExportAllChannelBackups returns static channel backups for all existing channels known to lnd. A set of regular singular static channel backups for each channel are returned. Additionally, a multi-channel backup is returned as well, which contains a single encrypted blob containing the backups of each channel.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ChanBackupExportRequest()
>>> response = stub.ExportAllChannelBackups(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"single_chan_backups": <ChannelBackups>,
"multi_chan_backup": <MultiChanBackup>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.exportAllChannelBackups(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "single_chan_backups": <ChannelBackups>,
// "multi_chan_backup": <MultiChanBackup>,
// }
This request has no parameters.
Parameter |
Type |
Description |
single_chan_backups |
ChannelBackups |
The set of new channels that have been added since the last channel backup snapshot was requested. |
multi_chan_backup |
MultiChanBackup |
A multi-channel backup that covers all open channels currently known to lnd. |
ExportChannelBackup
Unary RPC
ExportChannelBackup attempts to return an encrypted static channel backup for the target channel identified by it channel point. The backup is encrypted with a key generated from the aezeed seed of the user. The returned backup can either be restored using the RestoreChannelBackup method once lnd is running, or via the InitWallet and UnlockWallet methods from the WalletUnlocker service.
# This command allows a user to export a Static Channel Backup (SCB) for
# a selected channel. SCB's are encrypted backups of a channel's initial
# state that are encrypted with a key derived from the seed of a user. In
# the case of partial or complete data loss, the SCB will allow the user
# to reclaim settled funds in the channel at its final state. The
# exported channel backups can be restored at a later time using the
# restorechanbackup command.
# This command will return one of two types of channel backups depending
# on the set of passed arguments:
# * If a target channel point is specified, then a single channel
# backup containing only the information for that channel will be
# returned.
# * If the --all flag is passed, then a multi-channel backup will be
# returned. A multi backup is a single encrypted blob (displayed in
# hex encoding) that contains several channels in a single cipher
# text.
# Both of the backup types can be restored using the restorechanbackup
# command.
$ lncli exportchanbackup [command options] [chan_point] [--all] [--output_file]
# --chan_point value the target channel to obtain an SCB for
# --all if specified, then a multi backup of all active channels will be returned
# --output_file value if specified, then rather than printing a JSON output
# of the static channel backup, a serialized version of
# the backup (either Single or Multi) will be written to
# the target file, this is the same format used by lnd in
# its channel.backup file
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ExportChannelBackupRequest(
chan_point=<ChannelPoint>,
)
>>> response = stub.ExportChannelBackup(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"chan_point": <ChannelPoint>,
"chan_backup": <bytes>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
chan_point: <ChannelPoint>,
};
lightning.exportChannelBackup(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "chan_point": <ChannelPoint>,
// "chan_backup": <bytes>,
// }
Parameter |
Type |
Description |
chan_point |
ChannelPoint |
The target channel point to obtain a back up for. |
Parameter |
Type |
Description |
chan_point |
ChannelPoint |
Identifies the channel that this backup belongs to. |
chan_backup |
bytes |
Is an encrypted single-chan backup. this can be passed to RestoreChannelBackups, or the WalletUnlocker Init and Unlock methods in order to trigger the recovery protocol. When using REST, this field must be encoded as base64. |
FeeReport
Unary RPC
FeeReport allows the caller to obtain a report detailing the current fee schedule enforced by the node globally for each channel.
# Returns the current fee policies of all active channels.
# Fee policies can be updated using the updatechanpolicy command.
$ lncli feereport [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.FeeReportRequest()
>>> response = stub.FeeReport(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"channel_fees": <array ChannelFeeReport>,
"day_fee_sum": <uint64>,
"week_fee_sum": <uint64>,
"month_fee_sum": <uint64>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.feeReport(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "channel_fees": <array ChannelFeeReport>,
// "day_fee_sum": <uint64>,
// "week_fee_sum": <uint64>,
// "month_fee_sum": <uint64>,
// }
This request has no parameters.
Parameter |
Type |
Description |
channel_fees |
array ChannelFeeReport |
An array of channel fee reports which describes the current fee schedule for each channel. |
day_fee_sum |
uint64 |
The total amount of fee revenue (in satoshis) the switch has collected over the past 24 hrs. |
week_fee_sum |
uint64 |
The total amount of fee revenue (in satoshis) the switch has collected over the past 1 week. |
month_fee_sum |
uint64 |
The total amount of fee revenue (in satoshis) the switch has collected over the past 1 month. |
ForwardingHistory
Unary RPC
ForwardingHistory allows the caller to query the htlcswitch for a record of all HTLCs forwarded within the target time range, and integer offset within that time range, for a maximum number of events. If no maximum number of events is specified, up to 100 events will be returned. If no time-range is specified, then events will be returned in the order that they occured. A list of forwarding events are returned. The size of each forwarding event is 40 bytes, and the max message size able to be returned in gRPC is 4 MiB. As a result each message can only contain 50k entries. Each response has the index offset of the last entry. The index offset can be provided to the request to allow the caller to skip a series of records.
# Query the HTLC switch's internal forwarding log for all completed
# payment circuits (HTLCs) over a particular time range (--start_time and
# --end_time). The start and end times are meant to be expressed in
# seconds since the Unix epoch.
# Alternatively negative time ranges can be used, e.g. "-3d". Supports
# s(seconds), m(minutes), h(ours), d(ays), w(eeks), M(onths), y(ears).
# Month equals 30.44 days, year equals 365.25 days.
# If --start_time isn't provided, then 24 hours ago is used. If
# --end_time isn't provided, then the current time is used.
# The max number of events returned is 50k. The default number is 100,
# callers can use the --max_events param to modify this value.
# Finally, callers can skip a series of events using the --index_offset
# parameter. Each response will contain the offset index of the last
# entry. Using this callers can manually paginate within a time slice.
$ lncli fwdinghistory [command options] start_time [end_time] [index_offset] [max_events]
# --start_time value the starting time for the query as unix timestamp or relative e.g. "-1w"
# --end_time value the end time for the query as unix timestamp or relative e.g. "-1w"
# --index_offset value the number of events to skip (default: 0)
# --max_events value the max number of events to return (default: 0)
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ForwardingHistoryRequest(
start_time=<uint64>,
end_time=<uint64>,
index_offset=<uint32>,
num_max_events=<uint32>,
)
>>> response = stub.ForwardingHistory(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"forwarding_events": <array ForwardingEvent>,
"last_offset_index": <uint32>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
start_time: <uint64>,
end_time: <uint64>,
index_offset: <uint32>,
num_max_events: <uint32>,
};
lightning.forwardingHistory(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "forwarding_events": <array ForwardingEvent>,
// "last_offset_index": <uint32>,
// }
Parameter |
Type |
Description |
start_time |
uint64 |
Start time is the starting point of the forwarding history request. All records beyond this point will be included, respecting the end time, and the index offset. |
end_time |
uint64 |
End time is the end point of the forwarding history request. The response will carry at most 50k records between the start time and the end time. The index offset can be used to implement pagination. |
index_offset |
uint32 |
Index offset is the offset in the time series to start at. As each response can only contain 50k records, callers can use this to skip around within a packed time series. |
num_max_events |
uint32 |
The max number of events to return in the response to this query. |
Parameter |
Type |
Description |
forwarding_events |
array ForwardingEvent |
A list of forwarding events from the time slice of the time series specified in the request. |
last_offset_index |
uint32 |
The index of the last time in the set of returned forwarding events. Can be used to seek further, pagination style. |
FundingStateStep
Unary RPC
FundingStateStep is an advanced funding related call that allows the caller to either execute some preparatory steps for a funding workflow, or manually progress a funding workflow. The primary way a funding flow is identified is via its pending channel ID. As an example, this method can be used to specify that we're expecting a funding flow for a particular pending channel ID, for which we need to use specific parameters. Alternatively, this can be used to interactively drive PSBT signing for funding for partially complete funding transactions.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.FundingTransitionMsg(
shim_register=<FundingShim>,
shim_cancel=<FundingShimCancel>,
psbt_verify=<FundingPsbtVerify>,
psbt_finalize=<FundingPsbtFinalize>,
)
>>> response = stub.FundingStateStep(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
shim_register: <FundingShim>,
shim_cancel: <FundingShimCancel>,
psbt_verify: <FundingPsbtVerify>,
psbt_finalize: <FundingPsbtFinalize>,
};
lightning.fundingStateStep(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// }
Parameter |
Type |
Description |
shim_register |
FundingShim |
The funding shim to register. This should be used before any channel funding has began by the remote party, as it is intended as a preparatory step for the full channel funding. |
shim_cancel |
FundingShimCancel |
Used to cancel an existing registered funding shim. |
psbt_verify |
FundingPsbtVerify |
Used to continue a funding flow that was initiated to be executed through a PSBT. This step verifies that the PSBT contains the correct outputs to fund the channel. |
psbt_finalize |
FundingPsbtFinalize |
Used to continue a funding flow that was initiated to be executed through a PSBT. This step finalizes the funded and signed PSBT, finishes negotiation with the peer and finally publishes the resulting funding transaction. |
This response has no parameters.
GetChanInfo
Unary RPC
GetChanInfo returns the latest authenticated network announcement for the given channel identified by its channel ID: an 8-byte integer which uniquely identifies the location of transaction's funding output within the blockchain.
# Prints out the latest authenticated state for a particular channel
$ lncli getchaninfo [command options] chan_id
# --chan_id value the 8-byte compact channel ID to query for (default: 0)
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ChanInfoRequest(
chan_id=<uint64>,
)
>>> response = stub.GetChanInfo(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"channel_id": <uint64>,
"chan_point": <string>,
"last_update": <uint32>,
"node1_pub": <string>,
"node2_pub": <string>,
"capacity": <int64>,
"node1_policy": <RoutingPolicy>,
"node2_policy": <RoutingPolicy>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
chan_id: <uint64>,
};
lightning.getChanInfo(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "channel_id": <uint64>,
// "chan_point": <string>,
// "last_update": <uint32>,
// "node1_pub": <string>,
// "node2_pub": <string>,
// "capacity": <int64>,
// "node1_policy": <RoutingPolicy>,
// "node2_policy": <RoutingPolicy>,
// }
Parameter |
Type |
Description |
chan_id |
uint64 |
The unique channel ID for the channel. The first 3 bytes are the block height, the next 3 the index within the block, and the last 2 bytes are the output index for the channel. |
Parameter |
Type |
Description |
channel_id |
uint64 |
The unique channel ID for the channel. The first 3 bytes are the block height, the next 3 the index within the block, and the last 2 bytes are the output index for the channel. |
chan_point |
string |
|
last_update |
uint32 |
|
node1_pub |
string |
|
node2_pub |
string |
|
capacity |
int64 |
|
node1_policy |
RoutingPolicy |
|
node2_policy |
RoutingPolicy |
|
GetInfo
Unary RPC
GetInfo returns general information concerning the lightning node including it's identity pubkey, alias, the chains it is connected to, and information concerning the number of open+pending channels.
# Returns basic information related to the active daemon.
$ lncli getinfo [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.GetInfoRequest()
>>> response = stub.GetInfo(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"version": <string>,
"commit_hash": <string>,
"identity_pubkey": <string>,
"alias": <string>,
"color": <string>,
"num_pending_channels": <uint32>,
"num_active_channels": <uint32>,
"num_inactive_channels": <uint32>,
"num_peers": <uint32>,
"block_height": <uint32>,
"block_hash": <string>,
"best_header_timestamp": <int64>,
"synced_to_chain": <bool>,
"synced_to_graph": <bool>,
"testnet": <bool>,
"chains": <array Chain>,
"uris": <array string>,
"features": <array FeaturesEntry>,
"require_htlc_interceptor": <bool>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.getInfo(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "version": <string>,
// "commit_hash": <string>,
// "identity_pubkey": <string>,
// "alias": <string>,
// "color": <string>,
// "num_pending_channels": <uint32>,
// "num_active_channels": <uint32>,
// "num_inactive_channels": <uint32>,
// "num_peers": <uint32>,
// "block_height": <uint32>,
// "block_hash": <string>,
// "best_header_timestamp": <int64>,
// "synced_to_chain": <bool>,
// "synced_to_graph": <bool>,
// "testnet": <bool>,
// "chains": <array Chain>,
// "uris": <array string>,
// "features": <array FeaturesEntry>,
// "require_htlc_interceptor": <bool>,
// }
This request has no parameters.
Parameter |
Type |
Description |
version |
string |
The version of the LND software that the node is running. |
commit_hash |
string |
The SHA1 commit hash that the daemon is compiled with. |
identity_pubkey |
string |
The identity pubkey of the current node. |
alias |
string |
If applicable, the alias of the current node, e.g. "bob" |
color |
string |
The color of the current node in hex code format |
num_pending_channels |
uint32 |
Number of pending channels |
num_active_channels |
uint32 |
Number of active channels |
num_inactive_channels |
uint32 |
Number of inactive channels |
num_peers |
uint32 |
Number of peers |
block_height |
uint32 |
The node's current view of the height of the best block |
block_hash |
string |
The node's current view of the hash of the best block |
best_header_timestamp |
int64 |
Timestamp of the block best known to the wallet |
synced_to_chain |
bool |
Whether the wallet's view is synced to the main chain |
synced_to_graph |
bool |
Whether we consider ourselves synced with the public channel graph. |
testnet |
bool |
Whether the current node is connected to testnet. This field is deprecated and the network field should be used instead |
chains |
array Chain |
A list of active chains the node is connected to |
uris |
array string |
The URIs of the current node. |
features |
array FeaturesEntry |
Features that our node has advertised in our init message, node announcements and invoices. |
require_htlc_interceptor |
bool |
Indicates whether the HTLC interceptor API is in always-on mode. |
GetNetworkInfo
Unary RPC
GetNetworkInfo returns some basic stats about the known channel graph from the point of view of the node.
# Returns a set of statistics pertaining to the known channel graph
$ lncli getnetworkinfo [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.NetworkInfoRequest()
>>> response = stub.GetNetworkInfo(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"graph_diameter": <uint32>,
"avg_out_degree": <double>,
"max_out_degree": <uint32>,
"num_nodes": <uint32>,
"num_channels": <uint32>,
"total_network_capacity": <int64>,
"avg_channel_size": <double>,
"min_channel_size": <int64>,
"max_channel_size": <int64>,
"median_channel_size_sat": <int64>,
"num_zombie_chans": <uint64>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.getNetworkInfo(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "graph_diameter": <uint32>,
// "avg_out_degree": <double>,
// "max_out_degree": <uint32>,
// "num_nodes": <uint32>,
// "num_channels": <uint32>,
// "total_network_capacity": <int64>,
// "avg_channel_size": <double>,
// "min_channel_size": <int64>,
// "max_channel_size": <int64>,
// "median_channel_size_sat": <int64>,
// "num_zombie_chans": <uint64>,
// }
This request has no parameters.
Parameter |
Type |
Description |
graph_diameter |
uint32 |
|
avg_out_degree |
double |
|
max_out_degree |
uint32 |
|
num_nodes |
uint32 |
|
num_channels |
uint32 |
|
total_network_capacity |
int64 |
|
avg_channel_size |
double |
|
min_channel_size |
int64 |
|
max_channel_size |
int64 |
|
median_channel_size_sat |
int64 |
|
num_zombie_chans |
uint64 |
The number of edges marked as zombies. |
GetNodeInfo
Unary RPC
GetNodeInfo returns the latest advertised, aggregated, and authenticated channel information for the specified node identified by its public key.
# Prints out the latest authenticated node state for an advertised node
$ lncli getnodeinfo [command options] [arguments...]
# --pub_key value the 33-byte hex-encoded compressed public of the target node
# --include_channels if true, will return all known channels associated with the node
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.NodeInfoRequest(
pub_key=<string>,
include_channels=<bool>,
)
>>> response = stub.GetNodeInfo(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"node": <LightningNode>,
"num_channels": <uint32>,
"total_capacity": <int64>,
"channels": <array ChannelEdge>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
pub_key: <string>,
include_channels: <bool>,
};
lightning.getNodeInfo(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "node": <LightningNode>,
// "num_channels": <uint32>,
// "total_capacity": <int64>,
// "channels": <array ChannelEdge>,
// }
Parameter |
Type |
Description |
pub_key |
string |
The 33-byte hex-encoded compressed public of the target node |
include_channels |
bool |
If true, will include all known channels associated with the node. |
Parameter |
Type |
Description |
node |
LightningNode |
An individual vertex/node within the channel graph. A node is connected to other nodes by one or more channel edges emanating from it. As the graph is directed, a node will also have an incoming edge attached to it for each outgoing edge. |
num_channels |
uint32 |
The total number of channels for the node. |
total_capacity |
int64 |
The sum of all channels capacity for the node, denominated in satoshis. |
channels |
array ChannelEdge |
A list of all public channels for the node. |
GetNodeMetrics
Unary RPC
GetNodeMetrics returns node metrics calculated from the graph. Currently the only supported metric is betweenness centrality of individual nodes.
# Prints out node metrics calculated from the current graph
$ lncli getnodemetrics [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.NodeMetricsRequest(
types=<array NodeMetricType>,
)
>>> response = stub.GetNodeMetrics(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"betweenness_centrality": <array BetweennessCentralityEntry>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
types: <array NodeMetricType>,
};
lightning.getNodeMetrics(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "betweenness_centrality": <array BetweennessCentralityEntry>,
// }
Parameter |
Type |
Description |
betweenness_centrality |
array BetweennessCentralityEntry |
Betweenness centrality is the sum of the ratio of shortest paths that pass through the node for each pair of nodes in the graph (not counting paths starting or ending at this node). Map of node pubkey to betweenness centrality of the node. Normalized values are in the [0,1] closed interval. |
GetRecoveryInfo
Unary RPC
GetRecoveryInfo returns information concerning the recovery mode including whether it's in a recovery mode, whether the recovery is finished, and the progress made so far.
# Display information about an ongoing recovery attempt.
$ lncli getrecoveryinfo [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.GetRecoveryInfoRequest()
>>> response = stub.GetRecoveryInfo(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"recovery_mode": <bool>,
"recovery_finished": <bool>,
"progress": <double>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.getRecoveryInfo(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "recovery_mode": <bool>,
// "recovery_finished": <bool>,
// "progress": <double>,
// }
This request has no parameters.
Parameter |
Type |
Description |
recovery_mode |
bool |
Whether the wallet is in recovery mode |
recovery_finished |
bool |
Whether the wallet recovery progress is finished |
progress |
double |
The recovery progress, ranging from 0 to 1. |
GetTransactions
Unary RPC
GetTransactions returns a list describing all the known transactions relevant to the wallet.
# List all transactions an address of the wallet was involved in.
# This call will return a list of wallet related transactions that paid
# to an address our wallet controls, or spent utxos that we held. The
# start_height and end_height flags can be used to specify an inclusive
# block range over which to query for transactions. If the end_height is
# less than the start_height, transactions will be queried in reverse.
# To get all transactions until the chain tip, including unconfirmed
# transactions (identifiable with BlockHeight=0), set end_height to -1.
# By default, this call will get all transactions our wallet was involved
# in, including unconfirmed transactions.
$ lncli listchaintxns [command options] [arguments...]
# --start_height value the block height from which to list transactions, inclusive (default: 0)
# --end_height value the block height until which to list transactions, inclusive, to get transactions until the chain tip, including unconfirmed, set this value to -1 (default: 0)
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.GetTransactionsRequest(
start_height=<int32>,
end_height=<int32>,
account=<string>,
)
>>> response = stub.GetTransactions(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"transactions": <array Transaction>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
start_height: <int32>,
end_height: <int32>,
account: <string>,
};
lightning.getTransactions(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "transactions": <array Transaction>,
// }
Parameter |
Type |
Description |
start_height |
int32 |
The height from which to list transactions, inclusive. If this value is greater than end_height, transactions will be read in reverse. |
end_height |
int32 |
The height until which to list transactions, inclusive. To include unconfirmed transactions, this value should be set to -1, which will return transactions from start_height until the current chain tip and unconfirmed transactions. If no end_height is provided, the call will default to this option. |
account |
string |
An optional filter to only include transactions relevant to an account. |
Parameter |
Type |
Description |
transactions |
array Transaction |
The list of transactions relevant to the wallet. |
ListChannels
Unary RPC
ListChannels returns a description of all the open channels that this node is a participant in.
# List all open channels.
$ lncli listchannels [command options] [arguments...]
# --active_only only list channels which are currently active
# --inactive_only only list channels which are currently inactive
# --public_only only list channels which are currently public
# --private_only only list channels which are currently private
# --peer value (optional) only display channels with a particular peer, accepts 66-byte, hex-encoded pubkeys
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ListChannelsRequest(
active_only=<bool>,
inactive_only=<bool>,
public_only=<bool>,
private_only=<bool>,
peer=<bytes>,
)
>>> response = stub.ListChannels(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"channels": <array Channel>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
active_only: <bool>,
inactive_only: <bool>,
public_only: <bool>,
private_only: <bool>,
peer: <bytes>,
};
lightning.listChannels(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "channels": <array Channel>,
// }
Parameter |
Type |
Description |
active_only |
bool |
|
inactive_only |
bool |
|
public_only |
bool |
|
private_only |
bool |
|
peer |
bytes |
Filters the response for channels with a target peer's pubkey. If peer is empty, all channels will be returned. |
Parameter |
Type |
Description |
channels |
array Channel |
The list of active channels |
ListInvoices
Unary RPC
ListInvoices returns a list of all the invoices currently stored within the database. Any active debug invoices are ignored. It has full support for paginated responses, allowing users to query for specific invoices through their add_index. This can be done by using either the first_index_offset or last_index_offset fields included in the response as the index_offset of the next request. By default, the first 100 invoices created will be returned. Backwards pagination is also supported through the Reversed flag.
# This command enables the retrieval of all invoices currently stored
# within the database. It has full support for paginationed responses,
# allowing users to query for specific invoices through their add_index.
# This can be done by using either the first_index_offset or
# last_index_offset fields included in the response as the index_offset of
# the next request. Backward pagination is enabled by default to receive
# current invoices first. If you wish to paginate forwards, set the
# paginate-forwards flag. If none of the parameters are specified, then
# the last 100 invoices will be returned.
# For example: if you have 200 invoices, "lncli listinvoices" will return
# the last 100 created. If you wish to retrieve the previous 100, the
# first_offset_index of the response can be used as the index_offset of
# the next listinvoices request.
$ lncli listinvoices [command options] [arguments...]
# --pending_only toggles if all invoices should be returned, or only those that are currently unsettled
# --index_offset value the index of an invoice that will be used as either the start or end of a query to determine which invoices should be returned in the response (default: 0)
# --max_invoices value the max number of invoices to return (default: 0)
# --paginate-forwards if set, invoices succeeding the index_offset will be returned
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ListInvoiceRequest(
pending_only=<bool>,
index_offset=<uint64>,
num_max_invoices=<uint64>,
reversed=<bool>,
)
>>> response = stub.ListInvoices(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"invoices": <array Invoice>,
"last_index_offset": <uint64>,
"first_index_offset": <uint64>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
pending_only: <bool>,
index_offset: <uint64>,
num_max_invoices: <uint64>,
reversed: <bool>,
};
lightning.listInvoices(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "invoices": <array Invoice>,
// "last_index_offset": <uint64>,
// "first_index_offset": <uint64>,
// }
Parameter |
Type |
Description |
pending_only |
bool |
If set, only invoices that are not settled and not canceled will be returned in the response. |
index_offset |
uint64 |
The index of an invoice that will be used as either the start or end of a query to determine which invoices should be returned in the response. |
num_max_invoices |
uint64 |
The max number of invoices to return in the response to this query. |
reversed |
bool |
If set, the invoices returned will result from seeking backwards from the specified index offset. This can be used to paginate backwards. |
Parameter |
Type |
Description |
invoices |
array Invoice |
A list of invoices from the time slice of the time series specified in the request. |
last_index_offset |
uint64 |
The index of the last item in the set of returned invoices. This can be used to seek further, pagination style. |
first_index_offset |
uint64 |
The index of the last item in the set of returned invoices. This can be used to seek backwards, pagination style. |
ListMacaroonIDs
Unary RPC
ListMacaroonIDs returns all root key IDs that are in use.
# List all macaroons root key IDs in use.
$ lncli listmacaroonids [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ListMacaroonIDsRequest()
>>> response = stub.ListMacaroonIDs(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"root_key_ids": <array uint64>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.listMacaroonIDs(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "root_key_ids": <array uint64>,
// }
This request has no parameters.
Parameter |
Type |
Description |
root_key_ids |
array uint64 |
The list of root key IDs that are in use. |
ListPayments
Unary RPC
ListPayments returns a list of all outgoing payments.
# This command enables the retrieval of payments stored
# in the database.
# Pagination is supported by the usage of index_offset in combination with
# the paginate_forwards flag.
# Reversed pagination is enabled by default to receive current payments
# first. Pagination can be resumed by using the returned last_index_offset
# (for forwards order), or first_index_offset (for reversed order) as the
# offset_index.
# Because counting all payments in the payment database can take a long
# time on systems with many payments, the count is not returned by
# default. That feature can be turned on with the --count_total_payments
# flag.
$ lncli listpayments [command options] [arguments...]
# --include_incomplete if set to true, payments still in flight (or failed) will be returned as well, keepingindices for payments the same as without the flag
# --index_offset value The index of a payment that will be used as either the start (in forwards mode) or end (in reverse mode) of a query to determine which payments should be returned in the response, where the index_offset is excluded. If index_offset is set to zero in reversed mode, the query will end with the last payment made. (default: 0)
# --max_payments value the max number of payments to return, by default, all completed payments are returned (default: 0)
# --paginate_forwards if set, payments succeeding the index_offset will be returned, allowing forwards pagination
# --count_total_payments if set, all payments (complete or incomplete, independent of max_payments parameter) will be counted; can take a long time on systems with many payments
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ListPaymentsRequest(
include_incomplete=<bool>,
index_offset=<uint64>,
max_payments=<uint64>,
reversed=<bool>,
count_total_payments=<bool>,
)
>>> response = stub.ListPayments(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"payments": <array Payment>,
"first_index_offset": <uint64>,
"last_index_offset": <uint64>,
"total_num_payments": <uint64>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
include_incomplete: <bool>,
index_offset: <uint64>,
max_payments: <uint64>,
reversed: <bool>,
count_total_payments: <bool>,
};
lightning.listPayments(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "payments": <array Payment>,
// "first_index_offset": <uint64>,
// "last_index_offset": <uint64>,
// "total_num_payments": <uint64>,
// }
Parameter |
Type |
Description |
include_incomplete |
bool |
If true, then return payments that have not yet fully completed. This means that pending payments, as well as failed payments will show up if this field is set to true. This flag doesn't change the meaning of the indices, which are tied to individual payments. |
index_offset |
uint64 |
The index of a payment that will be used as either the start or end of a query to determine which payments should be returned in the response. The index_offset is exclusive. In the case of a zero index_offset, the query will start with the oldest payment when paginating forwards, or will end with the most recent payment when paginating backwards. |
max_payments |
uint64 |
The maximal number of payments returned in the response to this query. |
reversed |
bool |
If set, the payments returned will result from seeking backwards from the specified index offset. This can be used to paginate backwards. The order of the returned payments is always oldest first (ascending index order). |
count_total_payments |
bool |
If set, all payments (complete and incomplete, independent of the max_payments parameter) will be counted. Note that setting this to true will increase the run time of the call significantly on systems that have a lot of payments, as all of them have to be iterated through to be counted. |
Parameter |
Type |
Description |
payments |
array Payment |
The list of payments |
first_index_offset |
uint64 |
The index of the first item in the set of returned payments. This can be used as the index_offset to continue seeking backwards in the next request. |
last_index_offset |
uint64 |
The index of the last item in the set of returned payments. This can be used as the index_offset to continue seeking forwards in the next request. |
total_num_payments |
uint64 |
Will only be set if count_total_payments in the request was set. Represents the total number of payments (complete and incomplete, independent of the number of payments requested in the query) currently present in the payments database. |
ListPeers
Unary RPC
ListPeers returns a verbose listing of all currently active peers.
# List all active, currently connected peers.
$ lncli listpeers [command options] [arguments...]
# --list_errors list a full set of most recent errors for the peer
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ListPeersRequest(
latest_error=<bool>,
)
>>> response = stub.ListPeers(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"peers": <array Peer>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
latest_error: <bool>,
};
lightning.listPeers(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "peers": <array Peer>,
// }
Parameter |
Type |
Description |
latest_error |
bool |
If true, only the last error that our peer sent us will be returned with the peer's information, rather than the full set of historic errors we have stored. |
Parameter |
Type |
Description |
peers |
array Peer |
The list of currently connected peers |
ListPermissions
Unary RPC
ListPermissions lists all RPC method URIs and their required macaroon permissions to access them.
# Lists all RPC method URIs and the macaroon permissions they require to be invoked.
$ lncli listpermissions [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ListPermissionsRequest()
>>> response = stub.ListPermissions(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"method_permissions": <array MethodPermissionsEntry>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.listPermissions(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "method_permissions": <array MethodPermissionsEntry>,
// }
This request has no parameters.
Parameter |
Type |
Description |
method_permissions |
array MethodPermissionsEntry |
A map between all RPC method URIs and their required macaroon permissions to access them. |
ListUnspent
Unary RPC
Deprecated, use walletrpc.ListUnspent instead. ListUnspent returns a list of all utxos spendable by the wallet with a number of confirmations between the specified minimum and maximum.
# For each spendable utxo currently in the wallet, with at least min_confs
# confirmations, and at most max_confs confirmations, lists the txid,
# index, amount, address, address type, scriptPubkey and number of
# confirmations. Use --min_confs=0 to include unconfirmed coins. To list
# all coins with at least min_confs confirmations, omit the second
# argument or flag '--max_confs'. To list all confirmed and unconfirmed
# coins, no arguments are required. To see only unconfirmed coins, use
# '--unconfirmed_only' with '--min_confs' and '--max_confs' set to zero or
# not present.
$ lncli listunspent [command options] [min-confs [max-confs]] [--unconfirmed_only]
# --min_confs value the minimum number of confirmations for a utxo (default: 0)
# --max_confs value the maximum number of confirmations for a utxo (default: 0)
# --unconfirmed_only when min_confs and max_confs are zero, setting false implicitly overrides max_confs to be MaxInt32, otherwise max_confs remains zero. An error is returned if the value is true and both min_confs and max_confs are non-zero. (default: false)
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.ListUnspentRequest(
min_confs=<int32>,
max_confs=<int32>,
account=<string>,
)
>>> response = stub.ListUnspent(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"utxos": <array Utxo>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
min_confs: <int32>,
max_confs: <int32>,
account: <string>,
};
lightning.listUnspent(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "utxos": <array Utxo>,
// }
Parameter |
Type |
Description |
min_confs |
int32 |
The minimum number of confirmations to be included. |
max_confs |
int32 |
The maximum number of confirmations to be included. |
account |
string |
An optional filter to only include outputs belonging to an account. |
Parameter |
Type |
Description |
utxos |
array Utxo |
A list of utxos |
LookupInvoice
Unary RPC
LookupInvoice attempts to look up an invoice according to its payment hash. The passed payment hash must be exactly 32 bytes, if not, an error is returned.
# Lookup an existing invoice by its payment hash.
$ lncli lookupinvoice [command options] rhash
# --rhash value the 32 byte payment hash of the invoice to query for, the hash should be a hex-encoded string
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.PaymentHash(
r_hash_str=<string>,
r_hash=<bytes>,
)
>>> response = stub.LookupInvoice(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"memo": <string>,
"r_preimage": <bytes>,
"r_hash": <bytes>,
"value": <int64>,
"value_msat": <int64>,
"settled": <bool>,
"creation_date": <int64>,
"settle_date": <int64>,
"payment_request": <string>,
"description_hash": <bytes>,
"expiry": <int64>,
"fallback_addr": <string>,
"cltv_expiry": <uint64>,
"route_hints": <array RouteHint>,
"private": <bool>,
"add_index": <uint64>,
"settle_index": <uint64>,
"amt_paid": <int64>,
"amt_paid_sat": <int64>,
"amt_paid_msat": <int64>,
"state": <InvoiceState>,
"htlcs": <array InvoiceHTLC>,
"features": <array FeaturesEntry>,
"is_keysend": <bool>,
"payment_addr": <bytes>,
"is_amp": <bool>,
"amp_invoice_state": <array AmpInvoiceStateEntry>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
r_hash_str: <string>,
r_hash: <bytes>,
};
lightning.lookupInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "memo": <string>,
// "r_preimage": <bytes>,
// "r_hash": <bytes>,
// "value": <int64>,
// "value_msat": <int64>,
// "settled": <bool>,
// "creation_date": <int64>,
// "settle_date": <int64>,
// "payment_request": <string>,
// "description_hash": <bytes>,
// "expiry": <int64>,
// "fallback_addr": <string>,
// "cltv_expiry": <uint64>,
// "route_hints": <array RouteHint>,
// "private": <bool>,
// "add_index": <uint64>,
// "settle_index": <uint64>,
// "amt_paid": <int64>,
// "amt_paid_sat": <int64>,
// "amt_paid_msat": <int64>,
// "state": <InvoiceState>,
// "htlcs": <array InvoiceHTLC>,
// "features": <array FeaturesEntry>,
// "is_keysend": <bool>,
// "payment_addr": <bytes>,
// "is_amp": <bool>,
// "amp_invoice_state": <array AmpInvoiceStateEntry>,
// }
Parameter |
Type |
Description |
r_hash_str |
string |
The hex-encoded payment hash of the invoice to be looked up. The passed payment hash must be exactly 32 bytes, otherwise an error is returned. Deprecated now that the REST gateway supports base64 encoding of bytes fields. |
r_hash |
bytes |
The payment hash of the invoice to be looked up. When using REST, this field must be encoded as base64. |
Parameter |
Type |
Description |
memo |
string |
An optional memo to attach along with the invoice. Used for record keeping purposes for the invoice's creator, and will also be set in the description field of the encoded payment request if the description_hash field is not being used. |
r_preimage |
bytes |
The hex-encoded preimage (32 byte) which will allow settling an incoming HTLC payable to this preimage. When using REST, this field must be encoded as base64. |
r_hash |
bytes |
The hash of the preimage. When using REST, this field must be encoded as base64. Note: Output only, don't specify for creating an invoice. |
value |
int64 |
The value of this invoice in satoshis The fields value and value_msat are mutually exclusive. |
value_msat |
int64 |
The value of this invoice in millisatoshis The fields value and value_msat are mutually exclusive. |
settled |
bool |
Whether this invoice has been fulfilled The field is deprecated. Use the state field instead (compare to SETTLED). |
creation_date |
int64 |
When this invoice was created. Note: Output only, don't specify for creating an invoice. |
settle_date |
int64 |
When this invoice was settled. Note: Output only, don't specify for creating an invoice. |
payment_request |
string |
A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient. Note: Output only, don't specify for creating an invoice. |
description_hash |
bytes |
Hash (SHA-256) of a description of the payment. Used if the description of payment (memo) is too long to naturally fit within the description field of an encoded payment request. When using REST, this field must be encoded as base64. |
expiry |
int64 |
Payment request expiry time in seconds. Default is 3600 (1 hour). |
fallback_addr |
string |
Fallback on-chain address. |
cltv_expiry |
uint64 |
Delta to use for the time-lock of the CLTV extended to the final hop. |
route_hints |
array RouteHint |
Route hints that can each be individually used to assist in reaching the invoice's destination. |
private |
bool |
Whether this invoice should include routing hints for private channels. |
add_index |
uint64 |
The "add" index of this invoice. Each newly created invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all added invoices with an add_index greater than this one. Note: Output only, don't specify for creating an invoice. |
settle_index |
uint64 |
The "settle" index of this invoice. Each newly settled invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all settled invoices with an settle_index greater than this one. Note: Output only, don't specify for creating an invoice. |
amt_paid |
int64 |
Deprecated, use amt_paid_sat or amt_paid_msat. |
amt_paid_sat |
int64 |
The amount that was accepted for this invoice, in satoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it's possible that the sender paid MORE that was specified in the original invoice. So we'll record that here as well. Note: Output only, don't specify for creating an invoice. |
amt_paid_msat |
int64 |
The amount that was accepted for this invoice, in millisatoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it's possible that the sender paid MORE that was specified in the original invoice. So we'll record that here as well. Note: Output only, don't specify for creating an invoice. |
state |
InvoiceState |
The state the invoice is in. Note: Output only, don't specify for creating an invoice. |
htlcs |
array InvoiceHTLC |
List of HTLCs paying to this invoice [EXPERIMENTAL]. Note: Output only, don't specify for creating an invoice. |
features |
array FeaturesEntry |
List of features advertised on the invoice. Note: Output only, don't specify for creating an invoice. |
is_keysend |
bool |
Indicates if this invoice was a spontaneous payment that arrived via keysend [EXPERIMENTAL]. Note: Output only, don't specify for creating an invoice. |
payment_addr |
bytes |
The payment address of this invoice. This value will be used in MPP payments, and also for newer invoices that always require the MPP payload for added end-to-end security. Note: Output only, don't specify for creating an invoice. |
is_amp |
bool |
Signals whether or not this is an AMP invoice. |
amp_invoice_state |
array AmpInvoiceStateEntry |
[EXPERIMENTAL]: Maps a 32-byte hex-encoded set ID to the sub-invoice AMP state for the given set ID. This field is always populated for AMP invoices, and can be used along side LookupInvoice to obtain the HTLC information related to a given sub-invoice. Note: Output only, don't specify for creating an invoice. |
NewAddress
Unary RPC
NewAddress creates a new address under control of the local wallet.
# Generate a wallet new address. Address-types has to be one of:
# - p2wkh: Pay to witness key hash
# - np2wkh: Pay to nested witness key hash
# - p2tr: Pay to taproot pubkey
$ lncli newaddress [command options] address-type
# --account value (optional) the name of the account to generate a new address for
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.NewAddressRequest(
type=<AddressType>,
account=<string>,
)
>>> response = stub.NewAddress(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"address": <string>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
type: <AddressType>,
account: <string>,
};
lightning.newAddress(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "address": <string>,
// }
Parameter |
Type |
Description |
type |
AddressType |
The type of address to generate. |
account |
string |
The name of the account to generate a new address for. If empty, the default wallet account is used. |
Parameter |
Type |
Description |
address |
string |
The newly generated wallet address |
OpenChannel
Server-streaming RPC
OpenChannel attempts to open a singly funded channel specified in the request to a remote peer. Users are able to specify a target number of blocks that the funding transaction should be confirmed in, or a manual fee rate to us for the funding transaction. If neither are specified, then a lax block confirmation target is used. Each OpenStatusUpdate will return the pending channel ID of the in-progress channel. Depending on the arguments specified in the OpenChannelRequest, this pending channel ID can then be used to manually progress the channel funding flow.
# Attempt to open a new channel to an existing peer with the key node-key
# optionally blocking until the channel is 'open'.
# One can also connect to a node before opening a new channel to it by
# setting its host:port via the --connect argument. For this to work,
# the node_key must be provided, rather than the peer_id. This is optional.
# The channel will be initialized with local-amt satoshis local and push-amt
# satoshis for the remote node. Note that specifying push-amt means you give that
# amount to the remote node as part of the channel opening. Once the channel is open,
# a channelPoint (txid:vout) of the funding output is returned.
# If the remote peer supports the option upfront shutdown feature bit (query
# listpeers to see their supported feature bits), an address to enforce
# payout of funds on cooperative close can optionally be provided. Note that
# if you set this value, you will not be able to cooperatively close out to
# another address.
# One can manually set the fee to be used for the funding transaction via either
# the --conf_target or --sat_per_vbyte arguments. This is optional.
$ lncli openchannel [command options] node-key local-amt push-amt
# --node_key value the identity public key of the target node/peer serialized in compressed format
# --connect value (optional) the host:port of the target node
# --local_amt value the number of satoshis the wallet should commit to the channel (default: 0)
# --push_amt value the number of satoshis to give the remote side as part of the initial commitment state, this is equivalent to first opening a channel and sending the remote party funds, but done all in one step (default: 0)
# --block block and wait until the channel is fully open
# --conf_target value (optional) the number of blocks that the transaction *should* confirm in, will be used for fee estimation (default: 0)
# --sat_per_vbyte value (optional) a manual fee expressed in sat/vbyte that should be used when crafting the transaction (default: 0)
# --private make the channel private, such that it won't be announced to the greater network, and nodes other than the two channel endpoints must be explicitly told about it to be able to route through it
# --min_htlc_msat value (optional) the minimum value we will require for incoming HTLCs on the channel (default: 0)
# --remote_csv_delay value (optional) the number of blocks we will require our channel counterparty to wait before accessing its funds in case of unilateral close. If this is not set, we will scale the value according to the channel size (default: 0)
# --max_local_csv value (optional) the maximum number of blocks that we will allow the remote peer to require we wait before accessing our funds in the case of a unilateral close. (default: 0)
# --min_confs value (optional) the minimum number of confirmations each one of your outputs used for the funding transaction must satisfy (default: 1)
# --close_address value (optional) an address to enforce payout of our funds to on cooperative close. Note that if this value is set on channel open, you will *not* be able to cooperatively close to a different address.
# --psbt start an interactive mode that initiates funding through a partially signed bitcoin transaction (PSBT), allowing the channel funds to be added and signed from a hardware or other offline device.
# --base_psbt value when using the interactive PSBT mode to open a new channel, use this base64 encoded PSBT as a base and add the new channel output to it instead of creating a new, empty one.
# --no_publish when using the interactive PSBT mode to open multiple channels in a batch, this flag instructs lnd to not publish the full batch transaction just yet. For safety reasons this flag should be set for each of the batch's transactions except the very last
# --remote_max_value_in_flight_msat value (optional) the maximum value in msat that can be pending within the channel at any given time (default: 0)
# --channel_type value (optional) the type of channel to propose to the remote peer ("tweakless", "anchors")
# --zero_conf (optional) whether a zero-conf channel open should be attempted.
# --scid_alias (optional) whether a scid-alias channel type should be negotiated.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.OpenChannelRequest(
sat_per_vbyte=<uint64>,
node_pubkey=<bytes>,
node_pubkey_string=<string>,
local_funding_amount=<int64>,
push_sat=<int64>,
target_conf=<int32>,
sat_per_byte=<int64>,
private=<bool>,
min_htlc_msat=<int64>,
remote_csv_delay=<uint32>,
min_confs=<int32>,
spend_unconfirmed=<bool>,
close_address=<string>,
funding_shim=<FundingShim>,
remote_max_value_in_flight_msat=<uint64>,
remote_max_htlcs=<uint32>,
max_local_csv=<uint32>,
commitment_type=<CommitmentType>,
zero_conf=<bool>,
scid_alias=<bool>,
)
>>> for response in stub.OpenChannel(request, metadata=[('macaroon', macaroon)]):
print(response)
{
"chan_pending": <PendingUpdate>,
"chan_open": <ChannelOpenUpdate>,
"psbt_fund": <ReadyForPsbtFunding>,
"pending_chan_id": <bytes>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
sat_per_vbyte: <uint64>,
node_pubkey: <bytes>,
node_pubkey_string: <string>,
local_funding_amount: <int64>,
push_sat: <int64>,
target_conf: <int32>,
sat_per_byte: <int64>,
private: <bool>,
min_htlc_msat: <int64>,
remote_csv_delay: <uint32>,
min_confs: <int32>,
spend_unconfirmed: <bool>,
close_address: <string>,
funding_shim: <FundingShim>,
remote_max_value_in_flight_msat: <uint64>,
remote_max_htlcs: <uint32>,
max_local_csv: <uint32>,
commitment_type: <CommitmentType>,
zero_conf: <bool>,
scid_alias: <bool>,
};
let call = lightning.openChannel(request);
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
// Console output:
// {
// "chan_pending": <PendingUpdate>,
// "chan_open": <ChannelOpenUpdate>,
// "psbt_fund": <ReadyForPsbtFunding>,
// "pending_chan_id": <bytes>,
// }
Parameter |
Type |
Description |
sat_per_vbyte |
uint64 |
A manual fee rate set in sat/vbyte that should be used when crafting the funding transaction. |
node_pubkey |
bytes |
The pubkey of the node to open a channel with. When using REST, this field must be encoded as base64. |
node_pubkey_string |
string |
The hex encoded pubkey of the node to open a channel with. Deprecated now that the REST gateway supports base64 encoding of bytes fields. |
local_funding_amount |
int64 |
The number of satoshis the wallet should commit to the channel |
push_sat |
int64 |
The number of satoshis to push to the remote side as part of the initial commitment state |
target_conf |
int32 |
The target number of blocks that the funding transaction should be confirmed by. |
sat_per_byte |
int64 |
Deprecated, use sat_per_vbyte. A manual fee rate set in sat/vbyte that should be used when crafting the funding transaction. |
private |
bool |
Whether this channel should be private, not announced to the greater network. |
min_htlc_msat |
int64 |
The minimum value in millisatoshi we will require for incoming HTLCs on the channel. |
remote_csv_delay |
uint32 |
The delay we require on the remote's commitment transaction. If this is not set, it will be scaled automatically with the channel size. |
min_confs |
int32 |
The minimum number of confirmations each one of your outputs used for the funding transaction must satisfy. |
spend_unconfirmed |
bool |
Whether unconfirmed outputs should be used as inputs for the funding transaction. |
close_address |
string |
Close address is an optional address which specifies the address to which funds should be paid out to upon cooperative close. This field may only be set if the peer supports the option upfront feature bit (call listpeers to check). The remote peer will only accept cooperative closes to this address if it is set. Note: If this value is set on channel creation, you will not be able to cooperatively close out to a different address. |
funding_shim |
FundingShim |
Funding shims are an optional argument that allow the caller to intercept certain funding functionality. For example, a shim can be provided to use a particular key for the commitment key (ideally cold) rather than use one that is generated by the wallet as normal, or signal that signing will be carried out in an interactive manner (PSBT based). |
remote_max_value_in_flight_msat |
uint64 |
The maximum amount of coins in millisatoshi that can be pending within the channel. It only applies to the remote party. |
remote_max_htlcs |
uint32 |
The maximum number of concurrent HTLCs we will allow the remote party to add to the commitment transaction. |
max_local_csv |
uint32 |
Max local csv is the maximum csv delay we will allow for our own commitment transaction. |
commitment_type |
CommitmentType |
The explicit commitment type to use. Note this field will only be used if the remote peer supports explicit channel negotiation. |
zero_conf |
bool |
If this is true, then a zero-conf channel open will be attempted. |
scid_alias |
bool |
If this is true, then an option-scid-alias channel-type open will be attempted. |
Parameter |
Type |
Description |
chan_pending |
PendingUpdate |
Signals that the channel is now fully negotiated and the funding transaction published. |
chan_open |
ChannelOpenUpdate |
Signals that the channel's funding transaction has now reached the required number of confirmations on chain and can be used. |
psbt_fund |
ReadyForPsbtFunding |
Signals that the funding process has been suspended and the construction of a PSBT that funds the channel PK script is now required. |
pending_chan_id |
bytes |
The pending channel ID of the created channel. This value may be used to further the funding flow manually via the FundingStateStep method. |
OpenChannelSync
Unary RPC
OpenChannelSync is a synchronous version of the OpenChannel RPC call. This call is meant to be consumed by clients to the REST proxy. As with all other sync calls, all byte slices are intended to be populated as hex encoded strings.
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.OpenChannelRequest(
sat_per_vbyte=<uint64>,
node_pubkey=<bytes>,
node_pubkey_string=<string>,
local_funding_amount=<int64>,
push_sat=<int64>,
target_conf=<int32>,
sat_per_byte=<int64>,
private=<bool>,
min_htlc_msat=<int64>,
remote_csv_delay=<uint32>,
min_confs=<int32>,
spend_unconfirmed=<bool>,
close_address=<string>,
funding_shim=<FundingShim>,
remote_max_value_in_flight_msat=<uint64>,
remote_max_htlcs=<uint32>,
max_local_csv=<uint32>,
commitment_type=<CommitmentType>,
zero_conf=<bool>,
scid_alias=<bool>,
)
>>> response = stub.OpenChannelSync(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"funding_txid_bytes": <bytes>,
"funding_txid_str": <string>,
"output_index": <uint32>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {
sat_per_vbyte: <uint64>,
node_pubkey: <bytes>,
node_pubkey_string: <string>,
local_funding_amount: <int64>,
push_sat: <int64>,
target_conf: <int32>,
sat_per_byte: <int64>,
private: <bool>,
min_htlc_msat: <int64>,
remote_csv_delay: <uint32>,
min_confs: <int32>,
spend_unconfirmed: <bool>,
close_address: <string>,
funding_shim: <FundingShim>,
remote_max_value_in_flight_msat: <uint64>,
remote_max_htlcs: <uint32>,
max_local_csv: <uint32>,
commitment_type: <CommitmentType>,
zero_conf: <bool>,
scid_alias: <bool>,
};
lightning.openChannelSync(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "funding_txid_bytes": <bytes>,
// "funding_txid_str": <string>,
// "output_index": <uint32>,
// }
Parameter |
Type |
Description |
sat_per_vbyte |
uint64 |
A manual fee rate set in sat/vbyte that should be used when crafting the funding transaction. |
node_pubkey |
bytes |
The pubkey of the node to open a channel with. When using REST, this field must be encoded as base64. |
node_pubkey_string |
string |
The hex encoded pubkey of the node to open a channel with. Deprecated now that the REST gateway supports base64 encoding of bytes fields. |
local_funding_amount |
int64 |
The number of satoshis the wallet should commit to the channel |
push_sat |
int64 |
The number of satoshis to push to the remote side as part of the initial commitment state |
target_conf |
int32 |
The target number of blocks that the funding transaction should be confirmed by. |
sat_per_byte |
int64 |
Deprecated, use sat_per_vbyte. A manual fee rate set in sat/vbyte that should be used when crafting the funding transaction. |
private |
bool |
Whether this channel should be private, not announced to the greater network. |
min_htlc_msat |
int64 |
The minimum value in millisatoshi we will require for incoming HTLCs on the channel. |
remote_csv_delay |
uint32 |
The delay we require on the remote's commitment transaction. If this is not set, it will be scaled automatically with the channel size. |
min_confs |
int32 |
The minimum number of confirmations each one of your outputs used for the funding transaction must satisfy. |
spend_unconfirmed |
bool |
Whether unconfirmed outputs should be used as inputs for the funding transaction. |
close_address |
string |
Close address is an optional address which specifies the address to which funds should be paid out to upon cooperative close. This field may only be set if the peer supports the option upfront feature bit (call listpeers to check). The remote peer will only accept cooperative closes to this address if it is set. Note: If this value is set on channel creation, you will not be able to cooperatively close out to a different address. |
funding_shim |
FundingShim |
Funding shims are an optional argument that allow the caller to intercept certain funding functionality. For example, a shim can be provided to use a particular key for the commitment key (ideally cold) rather than use one that is generated by the wallet as normal, or signal that signing will be carried out in an interactive manner (PSBT based). |
remote_max_value_in_flight_msat |
uint64 |
The maximum amount of coins in millisatoshi that can be pending within the channel. It only applies to the remote party. |
remote_max_htlcs |
uint32 |
The maximum number of concurrent HTLCs we will allow the remote party to add to the commitment transaction. |
max_local_csv |
uint32 |
Max local csv is the maximum csv delay we will allow for our own commitment transaction. |
commitment_type |
CommitmentType |
The explicit commitment type to use. Note this field will only be used if the remote peer supports explicit channel negotiation. |
zero_conf |
bool |
If this is true, then a zero-conf channel open will be attempted. |
scid_alias |
bool |
If this is true, then an option-scid-alias channel-type open will be attempted. |
Parameter |
Type |
Description |
funding_txid_bytes |
bytes |
Txid of the funding transaction. When using REST, this field must be encoded as base64. |
funding_txid_str |
string |
Hex-encoded string representing the byte-reversed hash of the funding transaction. |
output_index |
uint32 |
The index of the output of the funding transaction |
PendingChannels
Unary RPC
PendingChannels returns a list of all the channels that are currently considered "pending". A channel is pending if it has finished the funding workflow and is waiting for confirmations for the funding txn, or is in the process of closure, either initiated cooperatively or non-cooperatively.
# Display information pertaining to pending channels.
$ lncli pendingchannels [arguments...]
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.PendingChannelsRequest()
>>> response = stub.PendingChannels(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"total_limbo_balance": <int64>,
"pending_open_channels": <array PendingOpenChannel>,
"pending_closing_channels": <array ClosedChannel>,
"pending_force_closing_channels": <array ForceClosedChannel>,
"waiting_close_channels": <array WaitingCloseChannel>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
const macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const lndCert = fs.readFileSync('LND_DIR/tls.cert');
const sslCreds = grpc.credentials.createSsl(lndCert);
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let lightning = new lnrpc.Lightning('localhost:10009', creds);
let request = {};
lightning.pendingChannels(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "total_limbo_balance": <int64>,
// "pending_open_channels": <array PendingOpenChannel>,
// "pending_closing_channels": <array ClosedChannel>,
// "pending_force_closing_channels": <array ForceClosedChannel>,
// "waiting_close_channels": <array WaitingCloseChannel>,
// }
This request has no parameters.
Parameter |
Type |
Description |
total_limbo_balance |
int64 |
The balance in satoshis encumbered in pending channels |
pending_open_channels |
array PendingOpenChannel |
Channels pending opening |
pending_closing_channels |
array ClosedChannel |
Deprecated: Channels pending closing previously contained cooperatively closed channels with a single confirmation. These channels are now considered closed from the time we see them on chain. |
pending_force_closing_channels |
array ForceClosedChannel |
Channels pending force closing |
waiting_close_channels |
array WaitingCloseChannel |
Channels waiting for closing tx to confirm |
QueryRoutes
Unary RPC
QueryRoutes attempts to query the daemon's Channel Router for a possible route to a target destination capable of carrying a specific amount of satoshis. The returned route contains the full details required to craft and send an HTLC, also including the necessary information that should be present within the Sphinx packet encapsulated within the HTLC. When using REST, the dest_custom_records
map type can be set by appending &dest_custom_records[<record_number>]=<record_data_base64_url_encoded>
to the URL. Unfortunately this map type doesn't appear in the REST API documentation because of a bug in the grpc-gateway library.
# Queries the channel router for a potential path to the destination that has sufficient flow for the amount including fees
$ lncli queryroutes [command options] dest amt
# --dest value the 33-byte hex-encoded public key for the payment destination
# --amt value the amount to send expressed in satoshis (default: 0)
# --fee_limit value maximum fee allowed in satoshis when sending the payment (default: 0)
# --fee_limit_percent value percentage of the payment's amount used as the maximum fee allowed when sending the payment (default: 0)
# --final_cltv_delta value (optional) number of blocks the last hop has to reveal the preimage (default: 0)
# --use_mc use mission control probabilities
# --outgoing_chanid value (optional) the channel id of the channel that must be taken to the first hop (default: 0)
# --ignore_pair value ignore directional node pair <node1>:<node2>. This flag can be specified multiple times if multiple node pairs are to be ignored
# --time_pref value (optional) expresses time preference (range -1 to 1) (default: 0)
# --cltv_limit value the maximum time lock that may be used for this payment (default: 0)
>>> import codecs, grpc, os
>>> # Generate the following 2 modules by compiling the lnrpc/lightning.proto with the grpcio-tools.
>>> # See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
>>> import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lightningstub.LightningStub(channel)
>>> request = lnrpc.QueryRoutesRequest(
pub_key=<string>,
amt=<int64>,
amt_msat=<int64>,
final_cltv_delta=<int32>,
fee_limit=<FeeLimit>,
ignored_nodes=<array bytes>,
ignored_edges=<array EdgeLocator>,
source_pub_key=<string>,
use_mission_control=<bool>,
ignored_pairs=<array NodePair>,
cltv_limit=<uint32>,
dest_custom_records=<array DestCustomRecordsEntry>,
outgoing_chan_id=<uint64>,
last_hop_pubkey=<bytes>,
route_hints=<array RouteHint>,
dest_features=<array FeatureBit>,
time_pref=<double>,
)
>>> response = stub.QueryRoutes(request, metadata=[('macaroon', macaroon)])
>>> print(response)
{
"routes": <array Route>,
"success_prob": <double>,
}
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
d