Sending Lightning Payments

Once you have outbound liquidity you can start sending payments too.

Rust
let use_trampoline = true;
// The `amount_msat` param is optional and should only passed if the bolt11 doesn't specify an amount.
// The amount_msat is required in case an amount is not specified in the bolt11 invoice'.
let optional_amount_msat: Option<u64> = None;
let optional_label = Some("<label>".to_string());

let req = SendPaymentRequest {
    bolt11: "...".into(),
    use_trampoline,
    amount_msat: optional_amount_msat,
    label: optional_label,
};
let response = sdk.send_payment(req).await?;
Swift
let useTrampoline = true
// The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount.
// The amountMsat is required in case an amount is not specified in the bolt11 invoice'.
let optionalAmountMsat: UInt64 = 3_000_000
let optionalLabel = "<label>"
let req = SendPaymentRequest(bolt11: "...", useTrampoline: useTrampoline, amountMsat: optionalAmountMsat, label: optionalLabel)
let response = try? sdk.sendPayment(req: req)
Kotlin
val bolt11 = "..."
try {
    val useTrampoline = true
    // The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount.
    // The amountMsat is required in case an amount is not specified in the bolt11 invoice'.
    val optionalAmountMsat = 3_000_000.toULong()
    val optionalLabel = "<label>"
    val req = SendPaymentRequest(bolt11, useTrampoline, optionalAmountMsat, optionalLabel)
    val response = sdk.sendPayment(req)
} catch (e: Exception) {
    // handle error
}
React Native
try {
  const bolt11 = 'bolt11 invoice'
  const useTrampoline = true
  // The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount.
  // The amountMsat is required in case an amount is not specified in the bolt11 invoice'.
  const optionalAmountMsat = 3000000
  const optionalLabel = '<label>'
  const response = await sendPayment({
    bolt11,
    useTrampoline,
    amountMsat: optionalAmountMsat,
    label: optionalLabel
  })
} catch (err) {
  console.error(err)
}
Dart
// The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount.
// The amountMsat is required in case an amount is not specified in the bolt11 invoice'.
bool useTrampoline = true;
int optionalAmountMsat = 3000000;
String optionalLabel = "<label>";

SendPaymentRequest req = SendPaymentRequest(bolt11: bolt11, useTrampoline: useTrampoline, amountMsat: optionalAmountMsat, label: optionalLabel);
SendPaymentResponse resp = await breezSDK.sendPayment(req: req);
Python
bolt11 = "..."
try:
    use_trampoline = True
    # The `amount_msat` param is optional and should only passed if the bolt11 doesn't specify an amount.
    # The amount_msat is required in case an amount is not specified in the bolt11 invoice'.
    optional_amount_msat = 3000000
    optional_label = "<label>"
    req = breez_sdk.SendPaymentRequest(bolt11=bolt11, use_trampoline=use_trampoline, amount_msat=optional_amount_msat, label=optional_label)
    sdk_services.send_payment(req=req)
except Exception as error:
    print(error)
    raise        
Go
bolt11 := "bolt11 invoice"
useTrampoline := true
// The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount.
// The amountMsat is required in case an amount is not specified in the bolt11 invoice'.
optionalAmountMsat := uint64(3_000_000)
optionalLabel := "<label>"
sendPaymentRequest := breez_sdk.SendPaymentRequest{
    Bolt11:        bolt11,
    UseTrampoline: useTrampoline,
    AmountMsat:    &optionalAmountMsat,
    Label:         &optionalLabel,
}
if response, err := sdk.SendPayment(sendPaymentRequest); err == nil {
    log.Printf("%#v", response)
}
C#
var bolt11 = "...";
var useTrampoline = true;
ulong optionalAmountMsat = 3_000_000;
var optionalLabel = "<label>";


try
{
    // The `amountMsat` param is optional and should only passed if the
    // bolt11 doesn't specify an amount.
    // The amountMsat is required in case an amount is not specified in
    // the bolt11 invoice.
    var response = sdk.SendPayment(
        new SendPaymentRequest(bolt11, useTrampoline, optionalAmountMsat, optionalLabel));
}
catch (Exception)
{
    // Handle error
}

Trampoline payments

In the above example, the use_trampoline flag is set to true to enable trampoline payments. With trampoline, pathfinding through the lightning network is outsourced to the LSP.

This has several benefits:

  • The payment is more reliable and faster as the LSP has a better view of the network topology and can find good routes faster.
  • There is less interaction between the user's app and the user's node in the cloud, improving payment speed.
  • Fees for lightning payments are fixed. That means fees can be displayed to the user before paying.

The trade-offs are:

  • The payment is less private as the LSP will learn the payment destination.

To disable trampoline payments, set use_trampoline to false. The user's node will then attempt to find routes directly, without outsourcing pathfinding to the LSP.