Fulfills one or more Spark invoices by paying them.
Method Signature
async fulfillSparkInvoice(
sparkInvoices: {
invoice: SparkAddressFormat;
amount?: bigint;
}[]
): Promise<FulfillSparkInvoiceResponse>
Parameters
Array of invoices to fulfill:
invoice: The Spark invoice to pay (must use spark1... prefix)
amount: Amount to pay (required for invoices without encoded amount)
Returns
response
FulfillSparkInvoiceResponse
required
Response containing results for all invoice payment attempts
Show FulfillSparkInvoiceResponse Type
interface FulfillSparkInvoiceResponse {
// Successfully paid sats invoices
satsTransactionSuccess: {
invoice: SparkAddressFormat;
transferResponse: WalletTransfer;
}[];
// Failed sats invoice payments
satsTransactionErrors: {
invoice: SparkAddressFormat;
error: Error;
}[];
// Successfully paid token invoices
tokenTransactionSuccess: {
tokenIdentifier: Bech32mTokenIdentifier;
invoices: SparkAddressFormat[];
txid: string;
}[];
// Failed token invoice payments
tokenTransactionErrors: {
tokenIdentifier: Bech32mTokenIdentifier;
invoices: SparkAddressFormat[];
error: Error;
}[];
// Invoices that failed validation before payment
invalidInvoices: {
invoice: SparkAddressFormat;
error: Error;
}[];
}
Example
// Pay a single invoice
const result = await wallet.fulfillSparkInvoice([
{ invoice: "spark1..." }
]);
// Pay multiple invoices with amounts
const batchResult = await wallet.fulfillSparkInvoice([
{ invoice: invoiceWithNoAmount, amount: 1000n },
{ invoice: invoiceWithEncodedAmount }
]);
// Check results
console.log("Successful:", result.satsTransactionSuccess);
console.log("Errors:", result.satsTransactionErrors);