GetInfo
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.
Source: lightning.proto
gRPC
rpc GetInfo (GetInfoRequest) returns (GetInfoResponse);
REST
HTTP Method | Path |
---|---|
GET | /v1/getinfo |
Code Samples
- gRPC
- REST
- Shell
- Javascript
- Python
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:10009'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
const TLS_PATH = 'LND_DIR/tls.cert'
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;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
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 client = new lnrpc.Lightning(GRPC_HOST, creds);
let request = {};
client.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": <Chain>,
// "uris": <string>,
// "features": <FeaturesEntry>,
// "require_htlc_interceptor": <bool>,
// "store_final_htlc_resolutions": <bool>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the 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
GRPC_HOST = 'localhost:10009'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = lightningstub.LightningStub(channel)
request = lnrpc.GetInfoRequest()
response = stub.GetInfo(request)
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": <Chain>,
# "uris": <string>,
# "features": <FeaturesEntry>,
# "require_htlc_interceptor": <bool>,
# "store_final_htlc_resolutions": <bool>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8080'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
let options = {
url: `https://${REST_HOST}/v1/getinfo`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
},
}
request.get(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "version": <string>, // <string>
// "commit_hash": <string>, // <string>
// "identity_pubkey": <string>, // <string>
// "alias": <string>, // <string>
// "color": <string>, // <string>
// "num_pending_channels": <integer>, // <uint32>
// "num_active_channels": <integer>, // <uint32>
// "num_inactive_channels": <integer>, // <uint32>
// "num_peers": <integer>, // <uint32>
// "block_height": <integer>, // <uint32>
// "block_hash": <string>, // <string>
// "best_header_timestamp": <string>, // <int64>
// "synced_to_chain": <boolean>, // <bool>
// "synced_to_graph": <boolean>, // <bool>
// "testnet": <boolean>, // <bool>
// "chains": <array>, // <Chain>
// "uris": <array>, // <string>
// "features": <object>, // <FeaturesEntry>
// "require_htlc_interceptor": <boolean>, // <bool>
// "store_final_htlc_resolutions": <boolean>, // <bool>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8080'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/getinfo'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
r = requests.get(url, headers=headers, verify=TLS_PATH)
print(r.json())
# {
# "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": <Chain>,
# "uris": <string>,
# "features": <FeaturesEntry>,
# "require_htlc_interceptor": <bool>,
# "store_final_htlc_resolutions": <bool>,
# }
$ lncli getinfo --help
NAME:
lncli getinfo - Returns basic information related to the active daemon.
USAGE:
lncli getinfo [arguments...]
Messages
lnrpc.GetInfoRequest
Source: lightning.proto
note
This request has no parameters.
lnrpc.GetInfoResponse
Source: lightning.proto
Field | gRPC Type | REST Type |
---|---|---|
version | string | string |
commit_hash | string | string |
identity_pubkey | string | string |
alias | string | string |
color | string | string |
num_pending_channels | uint32 | integer |
num_active_channels | uint32 | integer |
num_inactive_channels | uint32 | integer |
num_peers | uint32 | integer |
block_height | uint32 | integer |
block_hash | string | string |
best_header_timestamp | int64 | string |
synced_to_chain | bool | boolean |
synced_to_graph | bool | boolean |
testnet deprecated | bool | boolean |
chains | Chain[] | array |
uris | string[] | array |
features | FeaturesEntry[] | object |
require_htlc_interceptor | bool | boolean |
store_final_htlc_resolutions | bool | boolean |
Nested Messages
lnrpc.Chain
Field | gRPC Type | REST Type |
---|---|---|
chain deprecated | string | string |
network | string | string |
lnrpc.Feature
Field | gRPC Type | REST Type |
---|---|---|
name | string | string |
is_required | bool | boolean |
is_known | bool | boolean |
lnrpc.GetInfoResponse.FeaturesEntry
Field | gRPC Type | REST Type |
---|---|---|
key | uint32 | unknown |
value | Feature | unknown |