WDK logoWDK documentation

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

  1. Choose an amount in satoshis and an optional memo.
  2. Call account.createLightningInvoice().

You can create a BOLT11 invoice using account.createLightningInvoice():

Create Lightning Invoice
const invoice = await account.createLightningInvoice({
  amountSats: 50000,
  memo: 'Payment for services'
})
console.log('Lightning invoice:', invoice.invoice)

Pay a Lightning Invoice

  1. Obtain a BOLT11 encodedInvoice string.
  2. Set maxFeeSats to cap routing fees.
  3. Call account.payLightningInvoice().

You can pay an invoice using account.payLightningInvoice():

Pay Lightning Invoice
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:

Retry Lightning Payment Once
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():

Quote Lightning Payment Fee
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():

Get Lightning Send Request
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.

On this page