Lightning Payments
Create Lightning invoices, pay invoices, and inspect payment status.
This guide explains how to create a Lightning invoice, pay a Lightning invoice, estimate Lightning fees, and fetch a Lightning send request.
Create a Lightning Invoice
- Choose an amount in satoshis and an optional memo.
- Call
account.createLightningInvoice().
You can create a BOLT11 invoice using account.createLightningInvoice():
const invoice = await account.createLightningInvoice({
amountSats: 50000,
memo: 'Payment for services'
})
console.log('Lightning invoice:', invoice.invoice)Pay a Lightning Invoice
- Obtain a BOLT11
encodedInvoicestring. - Set
maxFeeSatsto cap routing fees. - Call
account.payLightningInvoice().
You can pay an invoice using account.payLightningInvoice():
const payment = await account.payLightningInvoice({
encodedInvoice: 'lnbc500u1p...',
maxFeeSats: 1000
})
console.log('Payment result:', payment)If you enable syncAndRetry, the wallet syncs state and retries account.payLightningInvoice() once after a failure:
const wallet = new WalletManagerSpark(seedPhrase, {
network: 'MAINNET',
syncAndRetry: true,
})
const account = await wallet.getAccount(0)
await account.payLightningInvoice({
encodedInvoice: 'lnbc500u1p...',
maxFeeSats: 1000,
})Estimate Lightning Fees
You can estimate the routing fee before paying using account.quotePayLightningInvoice():
const feeEstimate = await account.quotePayLightningInvoice({
encodedInvoice: 'lnbc500u1p...'
})
console.log('Fee estimate:', Number(feeEstimate), 'satoshis')Older references to getLightningSendFeeEstimate() map to quotePayLightningInvoice().
Fetch a Lightning Send Request
You can load a prior send request by id using account.getLightningSendRequest():
const sendRequest = await account.getLightningSendRequest(payment.id)
if (sendRequest) {
console.log('Payment status:', sendRequest.status)
}Use the id from the object returned by payLightningInvoice().
Next Steps
Learn how to handle Bitcoin layer 1 deposits and withdrawals.