REST API Examples
5 min
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
Interacting With Your Node's LND REST API
Here are some code snippets demonstrating how to interact with some of the most common and popular LND API methods:
const REST_HOST = 'node-name.m.voltageapp.io:8080';
const MACAROON = 'your-macaroon-in-hex-format'; // Replace this with your actual macaroon in hex format
const getInfo = async () => {
try {
const response = await fetch(`https://${REST_HOST}/v1/getinfo`, {
method: 'GET',
headers: {
'Grpc-Metadata-macaroon': MACAROON,
},
});
const data = await response.json();
console.log("getInfo", data)
} catch (error) {
console.error('Error:', error);
}
};const REST_HOST = 'node-name.m.voltageapp.io:8080';
const MACAROON = 'your-macaroon-in-hex-format'; // Replace this with your actual macaroon in hex format
const createInvoice = async () => {
try {
const response = await fetch(`https://${REST_HOST}/v1/invoices`, {
method: 'POST',
headers: {
'Grpc-Metadata-macaroon': MACAROON,
'Content-Type': 'application/json',
},
body: JSON.stringify({
value: 1000, // Invoice amount in satoshis
memo: 'Test invoice', // Optional memo for the invoice
}),
});
const data = await response.json();
setInvoice(data);
} catch (error) {
console.error('Error:', error);
}
};SendPaymentSync - https://lightning.engineering/api-docs/api/lnd/lightning/send-payment-sync
const REST_HOST = 'node-name.m.voltageapp.io:8080';
const MACAROON = 'your-macaroon-in-hex-format'; // Replace this with your actual macaroon in hex format
const payInvoice = async () => {
try {
const response = await fetch(`https://${REST_HOST}/v1/channels/transactions`, {
method: 'POST',
headers: {
'Grpc-Metadata-macaroon': MACAROON,
'Content-Type': 'application/json',
},
body: JSON.stringify({
payment_request: 'lnbc...', // Paste the invoice's payment request here
amt: 1000, // Amount to pay in satoshis
}),
});
const data = await response.json();
console.log("payInvoice", data)
} catch (error) {
console.error('Error:', error);
}
};
- POST /v1/channels/transactions: Pays an invoice by providing the payment request and the amount to pay.
- POST /v1/invoices: Creates a new invoice with a specified amount and optional memo.
- GET /v1/getinfo: Retrieves general information about your node.
Make sure to replace the placeholders in the script with your actual macaroon file path, node URL, and the desired invoice details.