Skip to main content
Methods for Lightning Network integration, including invoice creation, payment processing, and fee estimation.

payLightningInvoice(params: PayLightningInvoiceParams)

Pays a Lightning invoice.
interface PayLightningInvoiceParams {
  invoice: string;
  maxFeeSats: number;
  preferSpark?: boolean;
  amountSatsToSend?: number;
}

async payLightningInvoice(params: PayLightningInvoiceParams): Promise<LightningSendRequest>
Parameters:
  • params: Object containing:
    • invoice: The BOLT11-encoded Lightning invoice to pay.
    • maxFeeSats: Maximum fee in satoshis to pay for the invoice.
    • preferSpark: (Optional) Boolean that defaults to false. When preferSpark is set to true, Spark wallets will initiate a Spark transfer instead of a Lightning transfer if a valid Spark address is found in the invoice. If not, a regular Lightning payment will occur.
    • amountSatsToSend: (Optional) Amount in satoshis to send. This parameter is only used for zero-amount invoices. For regular invoices with a fixed amount, this parameter is ignored.
Returns:
  • Promise<LightningSendRequest>: The Lightning payment request details
Examples:
// Pay a regular invoice
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);

createLightningInvoice(params)

Creates a Lightning invoice for receiving payments.
interface CreateLightningInvoiceParams {
  amountSats: number;
  memo?: string;
  expirySeconds?: number;
  includeSparkAddress?: boolean;
  receiverIdentityPubkey?: string;
}

async createLightningInvoice(params: CreateLightningInvoiceParams): Promise<LightningReceiveRequest>
Parameters:
  • params: Object containing:
    • amountSats: Amount in satoshis
    • memo: (Optional) Description for the invoice
    • expirySeconds: (Optional) Expiry time in seconds, defaults to 30 days
    • includeSparkAddress: (Optional) By passing in true, a 36-byte string consisting of a recognizable header and a receiver’s compressed identity public key SPK:identitypubkey will get embedded in the fallback address (f) field of a BOLT11 invoice
    • receiverIdentityPubkey: (Optional) To generate an invoice for another Spark user, pass in the 33-byte compressed identity pubkey as a string
Returns:
  • Promise<LightningReceiveRequest>: The Lightning receive request details
Examples:
// Basic invoice
const invoice = await wallet.createLightningInvoice({
  amountSats: 100,
  memo: "test invoice",
});
console.log("Invoice:", invoice);

// Invoice with embedded Spark address
const invoiceWithSpark = await wallet.createLightningInvoice({
  amountSats: 100,
  memo: "Invoice with Spark integration",
  includeSparkAddress: true,
});
console.log("Invoice with Spark address:", invoiceWithSpark);

// Invoice for another Spark user
const invoiceForOther = await wallet.createLightningInvoice({
  amountSats: 100,
  memo: "Invoice for another user",
  receiverIdentityPubkey: "033b4f8cf891e45e2e3995e29b3c8b3d4d4e67f8a9b2c1d3e4f567890abcdef12",
});
console.log("Invoice for other user:", invoiceForOther);

getLightningReceiveRequest(id: string)

Gets the status of a Lightning receive request (invoice).
async getLightningReceiveRequest(id: string): Promise<LightningReceiveRequest | null>
Parameters:
  • id: The ID of the invoice to check.
Returns:
  • Promise<LightningReceiveRequest | null>: The Lightning receive request details or null if not found.

getLightningSendRequest(id: string)

Gets the status of a Lightning send request.
async getLightningSendRequest(id: string): Promise<LightningSendRequest | null>
Parameters:
  • id: The ID of the Lightning send request to check.
Returns:
  • Promise<LightningSendRequest | null>: The Lightning send request details or null if not found.

getLightningSendFeeEstimate(params)

Estimates the fee for sending a Lightning payment.
interface LightningSendFeeEstimateInput {
  encodedInvoice: string;
}

async getLightningSendFeeEstimate(params: LightningSendFeeEstimateInput): Promise<number>
Parameters:
  • params: Object containing:
    • encodedInvoice: The BOLT11-encoded Lightning invoice.
Returns:
  • Promise<number>: The estimated fee in satoshis.