Skip to main content
Pays a Lightning invoice via the SparkWallet.

Method Signature

interface PayLightningInvoiceParams {
  invoice: string;
  maxFeeSats: number;
  preferSpark?: boolean;
  amountSatsToSend?: number;
}

async payLightningInvoice(params: PayLightningInvoiceParams): Promise<LightningSendRequest | WalletTransfer>

Parameters

invoice
string
required
The BOLT11-encoded Lightning invoice to pay
maxFeeSats
number
required
Maximum fee in satoshis to pay for the invoice
preferSpark
boolean
When true, initiate a Spark transfer if a valid Spark address is found in the invoice (default: false)
amountSatsToSend
number
Amount in satoshis to send for zero-amount invoices

Returns

request
LightningSendRequest | WalletTransfer
required
The Lightning payment request details, or a WalletTransfer if preferSpark is true and a valid Spark address was found in the invoice
The payment preimage is not returned immediately. To retrieve the preimage after payment completes, call getLightningSendRequest(id) with the returned request ID.
When preferSpark: true and the invoice contains a valid Spark fallback address, the method returns a WalletTransfer instead of LightningSendRequest. If no valid Spark address is found, it falls back to Lightning.

Examples

// Pay a regular invoice via Lightning
const payment_response = await wallet.payLightningInvoice({
  invoice: "lnbc100n...", // Regular Lightning invoice with amount
  maxFeeSats: 5,
});
console.log("Payment Response:", payment_response);

// Pay a zero-amount invoice
const zeroAmountPayment = await wallet.payLightningInvoice({
  invoice: "lnbc...", // Zero-amount Lightning invoice
  maxFeeSats: 5,
  amountSatsToSend: 1000, // Specify amount for zero-amount invoice
});
console.log("Zero-amount Payment Response:", zeroAmountPayment);

// Prefer Spark transfer if invoice has Spark fallback address
const sparkPreferred = await wallet.payLightningInvoice({
  invoice: "lnbc100n...", // Invoice with Spark fallback
  maxFeeSats: 5,
  preferSpark: true, // Will use Spark transfer if available
});
// Returns WalletTransfer if Spark used, LightningSendRequest otherwise