> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spark.money/llms.txt
> Use this file to discover all available pages before exploring further.

# payLightningInvoice

> Pay a BOLT11 Lightning invoice.

Pays a Lightning invoice via the `SparkWallet`.

## Method Signature

```typescript theme={null}
interface PayLightningInvoiceParams {
  invoice: string;
  maxFeeSats: number;
  preferSpark?: boolean;
  amountSatsToSend?: number;
  idempotencyKey?: string;
}

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

## Parameters

<ResponseField name="invoice" type="string" required>
  The BOLT11-encoded Lightning invoice to pay
</ResponseField>

<ResponseField name="maxFeeSats" type="number" required>
  Maximum fee in satoshis to pay for the invoice
</ResponseField>

<ResponseField name="preferSpark" type="boolean">
  When `true`, initiate a Spark transfer if a valid Spark address is found in the invoice (default: `false`)
</ResponseField>

<ResponseField name="amountSatsToSend" type="number">
  Amount in satoshis to send for zero-amount invoices
</ResponseField>

<ResponseField name="idempotencyKey" type="string">
  Optional client-provided idempotency key for deduplication. Multiple requests with the same key will return the same result instead of creating duplicate payments or returning errors. Use this to prevent duplicate transactions when retrying failed requests.
</ResponseField>

## Returns

<ResponseField name="request" type="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
</ResponseField>

<Info>
  The payment preimage is not returned immediately. To retrieve the preimage after payment completes, call [`getLightningSendRequest(id)`](/api-reference/wallet/get-lightning-send-request) with the returned request ID.
</Info>

<Note>
  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.
</Note>

## Examples

```typescript theme={null}
// 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

// Use idempotency key to prevent duplicate payments
const idempotentPayment = await wallet.payLightningInvoice({
  invoice: "lnbc100n...",
  maxFeeSats: 5,
  idempotencyKey: "unique-payment-id-123", // Prevents duplicate if retried
});
// Safe to retry with same key - won't create duplicate payment
```
