Developer Resources
...
API Resources
LND Node API
GRPC API Examples
4min
prerequisites admin macaroon the admin macaroon is an authentication token that allows you to interact with your lnd node's grpc api with administrative permissions you can also grab a "read only" macaroon that wont have permissions to spend you can find your macaroons in your voltage dashboard by visiting manage access > macaroon bakery lightning proto file the lightning proto file is a protocol buffers (protobuf) definition file that defines the grpc service and messages used to interact with an lnd node it specifies the methods available for communication, as well as the structure of the request and response messages this file is essential for generating the client and server code needed to use the grpc api you can download the lightning proto file from the lnd github repository lnd github lnrpc directory https //github com/lightningnetwork/lnd/tree/master/lnrpc interacting with your node's lnd grpc api here are some code snippets demonstrating how to interact with some of the most common and popular lnd api methods using the grpc api getinfo https //lightning engineering/api docs/api/lnd/lightning/get info 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); async function main() { process env grpc ssl cipher suites = 'high+ecdsa'; let m = fs readfilesync(' /path/to/admin macaroon'); let macaroon = m tostring('hex'); // build meta data credentials let metadata = new grpc metadata(); metadata add('macaroon', macaroon); let macarooncreds = grpc credentials createfrommetadatagenerator((args, callback) => { callback(null, metadata); }); // build ssl credentials without needing to pass in the cert const sslcreds = grpc credentials createssl(); // combine the cert credentials and the macaroon auth credentials // such that every call is properly encrypted and authenticated let credentials = grpc credentials combinechannelcredentials(sslcreds, macarooncreds); // pass the credentials when creating a channel let lnrpcdescriptor = grpc loadpackagedefinition(packagedefinition); let lnrpc = lnrpcdescriptor lnrpc; let client = new lnrpc lightning('node name m voltageapp io 10009', credentials); client getinfo({}, (err, response) => { if (err) { console log('error ' + err); } console log('getinfo ', response); }); } main(); addinvoice https //lightning engineering/api docs/api/lnd/lightning/add invoice 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); async function main() { process env grpc ssl cipher suites = 'high+ecdsa'; let m = fs readfilesync(' /path/to/admin macaroon'); let macaroon = m tostring('hex'); // build meta data credentials let metadata = new grpc metadata(); metadata add('macaroon', macaroon); let macarooncreds = grpc credentials createfrommetadatagenerator((args, callback) => { callback(null, metadata); }); // build ssl credentials without needing to pass in the cert const sslcreds = grpc credentials createssl(); // combine the cert credentials and the macaroon auth credentials // such that every call is properly encrypted and authenticated let credentials = grpc credentials combinechannelcredentials(sslcreds, macarooncreds); // pass the credentials when creating a channel let lnrpcdescriptor = grpc loadpackagedefinition(packagedefinition); let lnrpc = lnrpcdescriptor lnrpc; let client = new lnrpc lightning('node name m voltageapp io 10009', credentials); let request = { value 1000, // invoice amount in satoshis memo 'test invoice', // optional memo for the invoice }; client addinvoice(request, (err, response) => { if (err) { console log('error ' + err); } console log('invoice ', response); }); } main(); sendpaymentsync https //lightning engineering/api docs/api/lnd/lightning/send payment sync 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); async function main() { process env grpc ssl cipher suites = 'high+ecdsa'; let m = fs readfilesync(' /path/to/admin macaroon'); let macaroon = m tostring('hex'); // build meta data credentials let metadata = new grpc metadata(); metadata add('macaroon', macaroon); let macarooncreds = grpc credentials createfrommetadatagenerator((args, callback) => { callback(null, metadata); }); // build ssl credentials without needing to pass in the cert const sslcreds = grpc credentials createssl(); // combine the cert credentials and the macaroon auth credentials // such that every call is properly encrypted and authenticated let credentials = grpc credentials combinechannelcredentials(sslcreds, macarooncreds); // pass the credentials when creating a channel let lnrpcdescriptor = grpc loadpackagedefinition(packagedefinition); let lnrpc = lnrpcdescriptor lnrpc; let client = new lnrpc lightning('node name m voltageapp io 10009', credentials); let request = { payment request 'lnbc ', // paste the invoice's payment request here amt 1000, // amount to pay in satoshis }; client sendpaymentsync(request, (err, response) => { if (err) { console log('error ' + err); } console log('payment ', response); }); } main(); this script demonstrates how to make three different api calls to your lnd node using the grpc api getinfo retrieves general information about your node addinvoice creates a new invoice with a specified amount and optional memo sendpaymentsync pays an invoice by providing the payment request and the amount to pay make sure to replace the placeholders in the script with your actual macaroon file path, tls certificate path, node url, and the desired invoice details