Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sending payments

Once the SDK is initialized, you can directly begin sending payments. The send process takes two steps:

  1. Preparing the Payment
  2. Sending the Payment

For sending payments via LNURL, see LNURL-Pay.

Preparing Payments API docs

During the prepare step, the SDK ensures that the inputs are valid with respect to the payment request type, and also returns the fees related to the payment so they can be confirmed.

The payment request field supports Lightning invoices, Bitcoin addresses and Spark addresses.

Lightning

BOLT11 invoice

For BOLT11 invoices the amount can be optionally set. The amount set in the request is only taken into account if it's an amountless invoice.

If the invoice also contains a Spark address, it means the payment can be sent directly with a Spark Transfer instead. When this is the case, the prepare response includes the Spark transfer fee.

Rust
let payment_request = "<bolt11 invoice>".to_string();
// Optionally set the amount you wish the pay the receiver
let optional_amount_sats = Some(5_000);
let prepare_response = sdk
    .prepare_send_payment(PrepareSendPaymentRequest {
        payment_request,
        amount_sats: optional_amount_sats,
    })
    .await?;

// If the fees are acceptable, continue to create the Send Payment
if let SendPaymentMethod::Bolt11Invoice {
    spark_transfer_fee_sats,
    lightning_fee_sats,
    ..
} = prepare_response.payment_method
{
    // Fees to pay via Lightning
    info!("Lightning Fees: {lightning_fee_sats} sats");
    // Or fees to pay (if available) via a Spark transfer
    info!("Spark Transfer Fees: {spark_transfer_fee_sats:?} sats");
}
Swift
let paymentRequest = "<bolt11 invoice>"
// Optionally set the amount you wish the pay the receiver
let optionalAmountSats: UInt64 = 5_000

let prepareResponse = try await sdk.prepareSendPayment(
    request: PrepareSendPaymentRequest (
        paymentRequest: paymentRequest,
        amountSats: optionalAmountSats
    ))

if case let .bolt11Invoice(_, sparkTransferFeeSats, lightningFeeSats) = prepareResponse.paymentMethod {
    // Fees to pay via Lightning
    print("Lightning Fee: \(lightningFeeSats) sats")
    // Or fees to pay (if available) via a Spark transfer
    if let sparkTransferFeeSats = sparkTransferFeeSats {
        print("Spark Transfer Fee: \(sparkTransferFeeSats) sats")
    }
}
Kotlin
val paymentRequest = "<bolt11 invoice>"
// Optionally set the amount you wish the pay the receiver
val optionalAmountSats = 5_000UL
try {
    val req = PrepareSendPaymentRequest(paymentRequest, optionalAmountSats)
    val prepareResponse = sdk.prepareSendPayment(req)

    // If the fees are acceptable, continue to create the Send Payment
    val paymentMethod = prepareResponse.paymentMethod
    if (paymentMethod is SendPaymentMethod.Bolt11Invoice) {
        // Fees to pay via Lightning
        val lightningFeeSats = paymentMethod.lightningFeeSats
        // Or fees to pay (if available) via a Spark transfer
        val sparkTransferFeeSats = paymentMethod.sparkTransferFeeSats
        // Log.v("Breez", "Lightning Fees: ${lightningFeeSats} sats")
        // Log.v("Breez", "Spark Transfer Fees: ${sparkTransferFeeSats} sats")
    }
} catch (e: Exception) {
    // handle error
}
Javascript
const paymentRequest = '<bolt11 invoice>'
// Optionally set the amount you wish the pay the receiver
const optionalAmountSats = 5_000

const prepareResponse = await sdk.prepareSendPayment({
  paymentRequest,
  amountSats: optionalAmountSats
})

// If the fees are acceptable, continue to create the Send Payment
if (prepareResponse.paymentMethod.type === 'bolt11Invoice') {
  // Fees to pay via Lightning
  const lightningFeeSats = prepareResponse.paymentMethod.lightningFeeSats
  // Or fees to pay (if available) via a Spark transfer
  const sparkTransferFeeSats = prepareResponse.paymentMethod.sparkTransferFeeSats
  console.debug(`Lightning Fees: ${lightningFeeSats} sats`)
  console.debug(`Spark Transfer Fees: ${sparkTransferFeeSats} sats`)
}
React Native
const paymentRequest = '<bolt11 invoice>'
// Optionally set the amount you wish the pay the receiver
const optionalAmountSats = BigInt(5_000)

const prepareResponse = await sdk.prepareSendPayment({
  paymentRequest,
  amountSats: optionalAmountSats
})

// If the fees are acceptable, continue to create the Send Payment
if (prepareResponse.paymentMethod instanceof SendPaymentMethod.Bolt11Invoice) {
  // Fees to pay via Lightning
  const lightningFeeSats = prepareResponse.paymentMethod.inner.lightningFeeSats
  // Or fees to pay (if available) via a Spark transfer
  const sparkTransferFeeSats = prepareResponse.paymentMethod.inner.sparkTransferFeeSats
  console.debug(`Lightning Fees: ${lightningFeeSats} sats`)
  console.debug(`Spark Transfer Fees: ${sparkTransferFeeSats} sats`)
}
Flutter
String paymentRequest = "<bolt11 invoice>";
// Optionally set the amount you wish the pay the receiver
BigInt optionalAmountSats = BigInt.from(5000);

final request = PrepareSendPaymentRequest(
    paymentRequest: paymentRequest, amountSats: optionalAmountSats);
final response = await sdk.prepareSendPayment(request: request);

// If the fees are acceptable, continue to create the Send Payment
final paymentMethod = response.paymentMethod;
if (paymentMethod is SendPaymentMethod_Bolt11Invoice) {
  // Fees to pay via Lightning
  final lightningFeeSats = paymentMethod.lightningFeeSats;
  // Or fees to pay (if available) via a Spark transfer
  final sparkTransferFeeSats = paymentMethod.sparkTransferFeeSats;
  print("Lightning Fees: $lightningFeeSats sats");
  print("Spark Transfer Fees: $sparkTransferFeeSats sats");
}
Python
payment_request = "<bolt11 invoice>"
# Optionally set the amount you wish the pay the receiver
optional_amount_sats = 5_000
try:
    request = PrepareSendPaymentRequest(
        payment_request=payment_request, amount_sats=optional_amount_sats
    )
    prepare_response = await sdk.prepare_send_payment(request=request)

    # If the fees are acceptable, continue to create the Send Payment
    if isinstance(
        prepare_response.payment_method, SendPaymentMethod.BOLT11_INVOICE
    ):
        # Fees to pay via Lightning
        lightning_fee_sats = prepare_response.payment_method.lightning_fee_sats
        # Or fees to pay (if available) via a Spark transfer
        spark_transfer_fee_sats = (
            prepare_response.payment_method.spark_transfer_fee_sats
        )
        logging.debug(f"Lightning Fees: {lightning_fee_sats} sats")
        logging.debug(f"Spark Transfer Fees: {spark_transfer_fee_sats} sats")
except Exception as error:
    logging.error(error)
    raise
Go
paymentRequest := "<bolt11 invoice>"
// Optionally set the amount you wish the pay the receiver
optionalAmountSats := uint64(5_000)

request := breez_sdk_spark.PrepareSendPaymentRequest{
    PaymentRequest: paymentRequest,
    AmountSats:     &optionalAmountSats,
}
response, err := sdk.PrepareSendPayment(request)

if sdkErr := err.(*breez_sdk_spark.SdkError); sdkErr != nil {
    return nil, err
}

// If the fees are acceptable, continue to create the Send Payment
switch paymentMethod := response.PaymentMethod.(type) {
case breez_sdk_spark.SendPaymentMethodBolt11Invoice:
    // Fees to pay via Lightning
    lightningFeeSats := paymentMethod.LightningFeeSats
    // Or fees to pay (if available) via a Spark transfer
    sparkTransferFeeSats := paymentMethod.SparkTransferFeeSats
    log.Printf("Lightning Fees: %v sats", lightningFeeSats)
    log.Printf("Spark Transfer Fees: %v sats", sparkTransferFeeSats)
}

Bitcoin

For Bitcoin addresses the amount must be set in the request. The prepare response includes fee quotes for three payment speeds: Slow, Medium and Fast.

Rust
let payment_request = "<bitcoin address>".to_string();
// Set the amount you wish the pay the receiver
let amount_sats = Some(50_000);
let prepare_response = sdk
    .prepare_send_payment(PrepareSendPaymentRequest {
        payment_request,
        amount_sats,
    })
    .await?;

// If the fees are acceptable, continue to create the Send Payment
if let SendPaymentMethod::BitcoinAddress { fee_quote, .. } = &prepare_response.payment_method {
    info!("Slow Fees: {} sats", fee_quote.speed_slow.total_fee_sat());
    info!(
        "Medium Fees: {} sats",
        fee_quote.speed_medium.total_fee_sat()
    );
    info!("Fast Fees: {} sats", fee_quote.speed_fast.total_fee_sat());
}
Swift
let paymentRequest = "<bitcoin address>"
// Set the amount you wish the pay the receiver
let amountSats: UInt64 = 50_000

let prepareResponse = try await sdk.prepareSendPayment(
    request: PrepareSendPaymentRequest (
        paymentRequest: paymentRequest,
        amountSats: amountSats
    ))

if case let .bitcoinAddress(_, feeQuote) = prepareResponse.paymentMethod {
    let slowFeeSats = feeQuote.speedSlow.userFeeSat + feeQuote.speedSlow.l1BroadcastFeeSat
    let mediumFeeSats = feeQuote.speedMedium.userFeeSat + feeQuote.speedMedium.l1BroadcastFeeSat
    let fastFeeSats = feeQuote.speedFast.userFeeSat + feeQuote.speedFast.l1BroadcastFeeSat
    print("Slow Fees: \(slowFeeSats) sats")
    print("Medium Fees: \(mediumFeeSats) sats")
    print("Fast Fees: \(fastFeeSats) sats")
}
Kotlin
val paymentRequest = "<bitcoin address>"
// Set the amount you wish the pay the receiver
val amountSats = 50_000UL
try {
    val req = PrepareSendPaymentRequest(paymentRequest, amountSats)
    val prepareResponse = sdk.prepareSendPayment(req)

    // If the fees are acceptable, continue to create the Send Payment
    val paymentMethod = prepareResponse.paymentMethod
    if (paymentMethod is SendPaymentMethod.BitcoinAddress) {
        val feeQuote = paymentMethod.feeQuote
        val slowFeeSats = feeQuote.speedSlow.userFeeSat + feeQuote.speedSlow.l1BroadcastFeeSat
        val mediumFeeSats = feeQuote.speedMedium.userFeeSat + feeQuote.speedMedium.l1BroadcastFeeSat
        val fastFeeSats = feeQuote.speedFast.userFeeSat + feeQuote.speedFast.l1BroadcastFeeSat
        // Log.v("Breez", "Slow Fees: ${slowFeeSats} sats")
        // Log.v("Breez", "Medium Fees: ${mediumFeeSats} sats")
        // Log.v("Breez", "Fast Fees: ${fastFeeSats} sats")
    }
} catch (e: Exception) {
    // handle error
}
Javascript
const paymentRequest = '<bitcoin address>'
// Set the amount you wish the pay the receiver
const amountSats = 50_000

const prepareResponse = await sdk.prepareSendPayment({
  paymentRequest,
  amountSats
})

// If the fees are acceptable, continue to create the Send Payment
if (prepareResponse.paymentMethod.type === 'bitcoinAddress') {
  const feeQuote = prepareResponse.paymentMethod.feeQuote
  const slowFeeSats = feeQuote.speedSlow.userFeeSat + feeQuote.speedSlow.l1BroadcastFeeSat
  const mediumFeeSats = feeQuote.speedMedium.userFeeSat + feeQuote.speedMedium.l1BroadcastFeeSat
  const fastFeeSats = feeQuote.speedFast.userFeeSat + feeQuote.speedFast.l1BroadcastFeeSat
  console.debug(`Slow Fees: ${slowFeeSats} sats`)
  console.debug(`Medium Fees: ${mediumFeeSats} sats`)
  console.debug(`Fast Fees: ${fastFeeSats} sats`)
}
React Native
const paymentRequest = '<bitcoin address>'
// Set the amount you wish the pay the receiver
const amountSats = BigInt(50_000)

const prepareResponse = await sdk.prepareSendPayment({
  paymentRequest,
  amountSats
})

// If the fees are acceptable, continue to create the Send Payment
if (prepareResponse.paymentMethod instanceof SendPaymentMethod.BitcoinAddress) {
  const feeQuote = prepareResponse.paymentMethod.inner.feeQuote
  const slowFeeSats = feeQuote.speedSlow.userFeeSat + feeQuote.speedSlow.l1BroadcastFeeSat
  const mediumFeeSats = feeQuote.speedMedium.userFeeSat + feeQuote.speedMedium.l1BroadcastFeeSat
  const fastFeeSats = feeQuote.speedFast.userFeeSat + feeQuote.speedFast.l1BroadcastFeeSat
  console.debug(`Slow Fees: ${slowFeeSats} sats`)
  console.debug(`Medium Fees: ${mediumFeeSats} sats`)
  console.debug(`Fast Fees: ${fastFeeSats} sats`)
}
Flutter
String paymentRequest = "<bitcoin address>";
// Set the amount you wish the pay the receiver
BigInt amountSats = BigInt.from(50000);

final request = PrepareSendPaymentRequest(
    paymentRequest: paymentRequest, amountSats: amountSats);
final response = await sdk.prepareSendPayment(request: request);

// If the fees are acceptable, continue to create the Send Payment
final paymentMethod = response.paymentMethod;
if (paymentMethod is SendPaymentMethod_BitcoinAddress) {
  final feeQuote = paymentMethod.feeQuote;
  final slowFeeSats =
      feeQuote.speedSlow.userFeeSat + feeQuote.speedSlow.l1BroadcastFeeSat;
  final mediumFeeSats = feeQuote.speedMedium.userFeeSat +
      feeQuote.speedMedium.l1BroadcastFeeSat;
  final fastFeeSats =
      feeQuote.speedFast.userFeeSat + feeQuote.speedFast.l1BroadcastFeeSat;
  print("Slow Fees: $slowFeeSats sats");
  print("Medium Fees: $mediumFeeSats sats");
  print("Fast Fees: $fastFeeSats sats");
}
Python
payment_request = "<bitcoin address>"
# Set the amount you wish the pay the receiver
amount_sats = 50_000
try:
    request = PrepareSendPaymentRequest(
        payment_request=payment_request, amount_sats=amount_sats
    )
    prepare_response = await sdk.prepare_send_payment(request=request)

    # If the fees are acceptable, continue to create the Send Payment
    if isinstance(
        prepare_response.payment_method, SendPaymentMethod.BITCOIN_ADDRESS
    ):
        fee_quote = prepare_response.payment_method.fee_quote
        slow_fee_sats = (
            fee_quote.speed_slow.user_fee_sat
            + fee_quote.speed_slow.l1_broadcast_fee_sat
        )
        medium_fee_sats = (
            fee_quote.speed_medium.user_fee_sat
            + fee_quote.speed_medium.l1_broadcast_fee_sat
        )
        fast_fee_sats = (
            fee_quote.speed_fast.user_fee_sat
            + fee_quote.speed_fast.l1_broadcast_fee_sat
        )
        logging.debug(f"Slow Fees: {slow_fee_sats} sats")
        logging.debug(f"Medium Fees: {medium_fee_sats} sats")
        logging.debug(f"Fast Fees: {fast_fee_sats} sats")
except Exception as error:
    logging.error(error)
    raise
Go
paymentRequest := "<bitcoin address>"
// Set the amount you wish the pay the receiver
amountSats := uint64(50_000)

request := breez_sdk_spark.PrepareSendPaymentRequest{
    PaymentRequest: paymentRequest,
    AmountSats:     &amountSats,
}
response, err := sdk.PrepareSendPayment(request)

if sdkErr := err.(*breez_sdk_spark.SdkError); sdkErr != nil {
    return nil, err
}

// If the fees are acceptable, continue to create the Send Payment
switch paymentMethod := response.PaymentMethod.(type) {
case breez_sdk_spark.SendPaymentMethodBitcoinAddress:
    feeQuote := paymentMethod.FeeQuote
    slowFeeQuote := feeQuote.SpeedSlow.UserFeeSat + feeQuote.SpeedSlow.L1BroadcastFeeSat
    mediumFeeQuote := feeQuote.SpeedMedium.UserFeeSat + feeQuote.SpeedMedium.L1BroadcastFeeSat
    fastFeeQuote := feeQuote.SpeedFast.UserFeeSat + feeQuote.SpeedFast.L1BroadcastFeeSat
    log.Printf("Slow Fees: %v sats", slowFeeQuote)
    log.Printf("Medium Fees: %v sats", mediumFeeQuote)
    log.Printf("Fast Fees: %v sats", fastFeeQuote)
}

Spark

For Spark addresses the amount must be set in the request. Sending to a Spark address uses a direct Spark transfer.

Rust
let payment_request = "<spark address>".to_string();
// Set the amount you wish the pay the receiver
let amount_sats = Some(50_000);
let prepare_response = sdk
    .prepare_send_payment(PrepareSendPaymentRequest {
        payment_request,
        amount_sats,
    })
    .await?;

// If the fees are acceptable, continue to create the Send Payment
if let SendPaymentMethod::SparkAddress { fee_sats, .. } = prepare_response.payment_method {
    info!("Fees: {} sats", fee_sats);
}
Swift
let paymentRequest = "<spark address>"
// Set the amount you wish the pay the receiver
let amountSats: UInt64 = 50_000

let prepareResponse = try await sdk.prepareSendPayment(
    request: PrepareSendPaymentRequest (
        paymentRequest: paymentRequest,
        amountSats: amountSats
    ))

if case let .sparkAddress(_, feeSats) = prepareResponse.paymentMethod {
    print("Fees: \(feeSats) sats")
}
Kotlin
val paymentRequest = "<spark address>"
// Set the amount you wish the pay the receiver
val amountSats = 50_000UL 
try {
    val req = PrepareSendPaymentRequest(paymentRequest, amountSats)
    val prepareResponse = sdk.prepareSendPayment(req)

    // If the fees are acceptable, continue to create the Send Payment
    val paymentMethod = prepareResponse.paymentMethod
    if (paymentMethod is SendPaymentMethod.SparkAddress) {
        val feeSats = paymentMethod.feeSats
        // Log.v("Breez", "Fees: ${feeSats} sats")
    }
} catch (e: Exception) {
    // handle error
}
Javascript
const paymentRequest = '<spark address>'
// Set the amount you wish the pay the receiver
const amountSats = 50_000

const prepareResponse = await sdk.prepareSendPayment({
  paymentRequest,
  amountSats
})

// If the fees are acceptable, continue to create the Send Payment
if (prepareResponse.paymentMethod.type === 'sparkAddress') {
  const feeSats = prepareResponse.paymentMethod.feeSats
  console.debug(`Fees: ${feeSats} sats`)
}
React Native
const paymentRequest = '<spark address>'
// Set the amount you wish the pay the receiver
const amountSats = BigInt(50_000)

const prepareResponse = await sdk.prepareSendPayment({
  paymentRequest,
  amountSats
})

// If the fees are acceptable, continue to create the Send Payment
if (prepareResponse.paymentMethod instanceof SendPaymentMethod.SparkAddress) {
  const feeSats = prepareResponse.paymentMethod.inner.feeSats
  console.debug(`Fees: ${feeSats} sats`)
}
Flutter

Python
payment_request = "<spark address>"
# Set the amount you wish the pay the receiver
amount_sats = 50_000
try:
    request = PrepareSendPaymentRequest(
        payment_request=payment_request, amount_sats=amount_sats
    )
    prepare_response = await sdk.prepare_send_payment(request=request)

    # If the fees are acceptable, continue to create the Send Payment
    if isinstance(prepare_response.payment_method, SendPaymentMethod.SPARK_ADDRESS):
        fee_sats = prepare_response.payment_method.fee_sats
        logging.debug(f"Fees: {fee_sats} sats")
except Exception as error:
    logging.error(error)
    raise
Go
paymentRequest := "<spark address>"
// Set the amount you wish the pay the receiver
amountSats := uint64(50_000)

request := breez_sdk_spark.PrepareSendPaymentRequest{
    PaymentRequest: paymentRequest,
    AmountSats:     &amountSats,
}
response, err := sdk.PrepareSendPayment(request)

if sdkErr := err.(*breez_sdk_spark.SdkError); sdkErr != nil {
    return nil, err
}

// If the fees are acceptable, continue to create the Send Payment
switch paymentMethod := response.PaymentMethod.(type) {
case breez_sdk_spark.SendPaymentMethodSparkAddress:
    feeSats := paymentMethod.FeeSats
    log.Printf("Fees: %v sats", feeSats)
}

Sending Payments API docs

Once the payment has been prepared, pass the prepare response as an argument to the send method and set any selected payment options.

Lightning

In the send payment options for BOLT11 invoices, you can set whether to prefer to use Spark to transfer the payment if the invoice contains a Spark address. By default, using Spark transfers are disabled.

Rust
let options = Some(SendPaymentOptions::Bolt11Invoice { prefer_spark: true });
let send_response = sdk
    .send_payment(SendPaymentRequest {
        prepare_response,
        options,
    })
    .await?;
let payment = send_response.payment;
info!("Payment: {payment:?}");
Swift
let options = SendPaymentOptions.bolt11Invoice(preferSpark: true)
let sendResponse = try await sdk.sendPayment(request: SendPaymentRequest (
    prepareResponse: prepareResponse,
    options: options
))
let payment = sendResponse.payment
Kotlin
try {
    val options = SendPaymentOptions.Bolt11Invoice(true)
    val sendResponse = sdk.sendPayment(SendPaymentRequest(prepareResponse, options))
    val payment = sendResponse.payment
} catch (e: Exception) {
    // handle error
}
Javascript
const options: SendPaymentOptions = { type: 'bolt11Invoice', preferSpark: true }
const sendResponse = await sdk.sendPayment({
  prepareResponse,
  options
})
const payment = sendResponse.payment
React Native
const options = new SendPaymentOptions.Bolt11Invoice({ preferSpark: true })
const sendResponse = await sdk.sendPayment({
  prepareResponse,
  options
})
const payment = sendResponse.payment
Flutter
final options = SendPaymentOptions.bolt11Invoice(preferSpark: true);
final request =
    SendPaymentRequest(prepareResponse: prepareResponse, options: options);
SendPaymentResponse response = await sdk.sendPayment(request: request);
Payment payment = response.payment;
Python
try:
    options = SendPaymentOptions.BOLT11_INVOICE(prefer_spark=True)
    request = SendPaymentRequest(prepare_response=prepare_response, options=options)
    send_response = await sdk.send_payment(request=request)
    payment = send_response.payment
except Exception as error:
    logging.error(error)
    raise
Go
var options breez_sdk_spark.SendPaymentOptions = breez_sdk_spark.SendPaymentOptionsBolt11Invoice{
    PreferSpark: true,
}

request := breez_sdk_spark.SendPaymentRequest{
    PrepareResponse: prepareResponse,
    Options:         &options,
}
response, err := sdk.SendPayment(request)

if sdkErr := err.(*breez_sdk_spark.SdkError); sdkErr != nil {
    return nil, err
}

payment := response.Payment

Bitcoin

For Bitcoin addresses you can set the confirmation speed in the send payment options. By default it's set to Fast.

Rust
// Send the payment, using Medium speed (Default = Fast)
let options = Some(SendPaymentOptions::BitcoinAddress {
    confirmation_speed: OnchainConfirmationSpeed::Medium,
});
let send_response = sdk
    .send_payment(SendPaymentRequest {
        prepare_response,
        options,
    })
    .await?;
let payment = send_response.payment;
info!("Payment: {payment:?}");
Swift
let options = SendPaymentOptions.bitcoinAddress(confirmationSpeed: .medium)
let sendResponse = try await sdk.sendPayment(request: SendPaymentRequest (
    prepareResponse: prepareResponse,
    options: options
))
let payment = sendResponse.payment
Kotlin
try {
    val options = SendPaymentOptions.BitcoinAddress(OnchainConfirmationSpeed.MEDIUM)
    val sendResponse = sdk.sendPayment(SendPaymentRequest(prepareResponse, options))
    val payment = sendResponse.payment
} catch (e: Exception) {
    // handle error
}
Javascript
const options: SendPaymentOptions = {
  type: 'bitcoinAddress',
  confirmationSpeed: 'medium'
}
const sendResponse = await sdk.sendPayment({
  prepareResponse,
  options
})
const payment = sendResponse.payment
React Native
const options = new SendPaymentOptions.BitcoinAddress({
  confirmationSpeed: OnchainConfirmationSpeed.Medium
})
const sendResponse = await sdk.sendPayment({
  prepareResponse,
  options
})
const payment = sendResponse.payment
Flutter
final options = SendPaymentOptions.bitcoinAddress(
    confirmationSpeed: OnchainConfirmationSpeed.medium);
final request =
    SendPaymentRequest(prepareResponse: prepareResponse, options: options);
SendPaymentResponse response = await sdk.sendPayment(request: request);
Payment payment = response.payment;
Python
try:
    options = SendPaymentOptions.BITCOIN_ADDRESS(
        confirmation_speed=OnchainConfirmationSpeed.MEDIUM
    )
    request = SendPaymentRequest(prepare_response=prepare_response, options=options)
    send_response = await sdk.send_payment(request=request)
    payment = send_response.payment
except Exception as error:
    logging.error(error)
    raise
Go
var options breez_sdk_spark.SendPaymentOptions = breez_sdk_spark.SendPaymentOptionsBitcoinAddress{
    ConfirmationSpeed: breez_sdk_spark.OnchainConfirmationSpeedMedium,
}

request := breez_sdk_spark.SendPaymentRequest{
    PrepareResponse: prepareResponse,
    Options:         &options,
}
response, err := sdk.SendPayment(request)

if sdkErr := err.(*breez_sdk_spark.SdkError); sdkErr != nil {
    return nil, err
}

payment := response.Payment

Spark

For Spark addresses no send payment options are needed.

Rust
// Send the payment
let send_response = sdk
    .send_payment(SendPaymentRequest {
        prepare_response,
        options: None,
    })
    .await?;
let payment = send_response.payment;
info!("Payment: {payment:?}");
Swift
let sendResponse = try await sdk.sendPayment(request: SendPaymentRequest (
    prepareResponse: prepareResponse,
    options: nil
))
let payment = sendResponse.payment
Kotlin
try {
    val sendResponse = sdk.sendPayment(SendPaymentRequest(prepareResponse, null))
    val payment = sendResponse.payment
} catch (e: Exception) {
    // handle error
}
Javascript
const sendResponse = await sdk.sendPayment({
  prepareResponse
})
const payment = sendResponse.payment
React Native
const sendResponse = await sdk.sendPayment({
  prepareResponse,
  options: undefined
})
const payment = sendResponse.payment
Flutter
final request = SendPaymentRequest(prepareResponse: prepareResponse);
SendPaymentResponse response = await sdk.sendPayment(request: request);
Payment payment = response.payment;
Python
try:
    request = SendPaymentRequest(prepare_response=prepare_response)
    send_response = await sdk.send_payment(request=request)
    payment = send_response.payment
except Exception as error:
    logging.error(error)
    raise
Go
request := breez_sdk_spark.SendPaymentRequest{
    PrepareResponse: prepareResponse,
}
response, err := sdk.SendPayment(request)

if sdkErr := err.(*breez_sdk_spark.SdkError); sdkErr != nil {
    return nil, err
}

payment := response.Payment

Event Flows

Once a send payment is initiated, you can follow and react to the different payment events using the guide below for each payment method. See Listening to events for how to subscribe to events.

EventDescriptionUX Suggestion
SyncedThe SDK has synced payments in the background.Update the payments list and balance. See listing payments and fetching the balance.

Lightning

EventDescriptionUX Suggestion
PaymentSucceededThe Lightning invoice has been paid either over Lightning or via a Spark transferUpdate the balance and show payment as complete.
PaymentFailedThe attempt to pay the Lightning invoice failed.

Bitcoin

EventDescriptionUX Suggestion
PaymentSucceededThe payment amount was successfully withdrawn onchain.Update the balance and show payment as complete.

Spark

EventDescriptionUX Suggestion
PaymentSucceededThe Spark transfer is complete.Update the balance and show payment as complete.