Receiving Lightning payments

With the Breez SDK you aren't required to open a channel and set up your inbound liquidity. The Breez SDK automatically connects your node to the LSP peer and you can now receive payments.

Rust
let receive_payment_response = sdk
    .receive_payment(ReceivePaymentRequest {
        amount_msat: 3_000_000,
        description: "Invoice for 3000 sats".into(),
        ..Default::default()
    })
    .await?;

let invoice = receive_payment_response.ln_invoice;
Swift
let receivePaymentResponse = try? sdk.receivePayment(
    req: ReceivePaymentRequest(
        amountMsat: 3_000_000,
        description: "Invoice for 3 000 sats"))

let invoice = receivePaymentResponse?.lnInvoice;
Kotlin
try {
    val receivePaymentResponse = sdk.receivePayment(ReceivePaymentRequest(
        3_000_000.toULong(),
        "Invoice for 3000 sats",
    ))

    val invoice = receivePaymentResponse.lnInvoice;
} catch (e: Exception) {
    // handle error
}
React Native
try {
  const receivePaymentResponse = await receivePayment({
    amountMsat: 3_000_000,
    description: 'Invoice for 3000 sats'
  })

  const invoice = receivePaymentResponse.lnInvoice
} catch (err) {
  console.error(err)
}
Dart
ReceivePaymentRequest req = const ReceivePaymentRequest(
  amountMsat: 3000000,
  description: "Invoice for 3000 sats",
);
ReceivePaymentResponse receivePaymentResponse = await BreezSDK().receivePayment(req: req);

print(receivePaymentResponse.lnInvoice);
Python
req = breez_sdk.ReceivePaymentRequest(
    amount_msat=3000000,
    description="Invoice for 3 000 sats")
receive_payment_response = sdk_services.receive_payment(req)

invoice = receive_payment_response.ln_invoice
Go
receivePaymentRequest := breez_sdk.ReceivePaymentRequest{
    AmountMsat:  uint64(3_000_000),
    Description: "Invoice for 3000 sats",
}
if receivePaymentResponse, err := sdk.ReceivePayment(receivePaymentRequest); err == nil {
    log.Printf("Invoice: %#v", receivePaymentResponse.LnInvoice)
}
C#
try
{
    var receivePaymentResponse = sdk.ReceivePayment(
        new ReceivePaymentRequest(3_000_000, "Invoice for 3000 sats"));

    var invoice = receivePaymentResponse.lnInvoice;
}
catch (Exception)
{
    // Handle error
}

Calculating fees

When the amount to be received exceeds the inbound liquidity of the node, a new channel will be opened by the LSP in order for the node to receive it. This can checked by retrieving the NodeState from the SDK and comparing the inbound liquidity to the amount to be received. If the amount is greater or equal to the inbound liquidity, a new channel opening is required.

To calculate the fees for a channel being opened by the LSP:

Rust
let channel_fees = sdk
    .open_channel_fee(OpenChannelFeeRequest {
        amount_msat,
        expiry: None,
    })
    .await?;
Swift
let response = try? sdk.openChannelFee(req: OpenChannelFeeRequest(amountMsat: amountMsat))
Kotlin
try {
    val amountMsat = 5_000.toULong();
    val channelFees = sdk.openChannelFee(OpenChannelFeeRequest(amountMsat))
} catch (e: Exception) {
    // handle error
}
React Native
try {
  const amountMsat = 10000
  const openChannelFeeResponse = await openChannelFee({
    amountMsat
  })
} catch (err) {
  console.error(err)
}
Dart
OpenChannelFeeRequest req = OpenChannelFeeRequest(amountMsat: amountMsat, expiry: expiry);
OpenChannelFeeResponse resp = await BreezSDK().openChannelFee(req: req);
print(resp.feeMsat);
Python
req = breez_sdk.OpenChannelFeeRequest(amount_msat)
channel_fees = sdk_services.open_channel_fee(req)
Go
if channelFees, err := sdk.OpenChannelFee(breez_sdk.OpenChannelFeeRequest{AmountMsat: amountMsat}); err == nil {
    log.Printf("%#v", channelFees)
}
C#
try
{
    var channelFees = sdk.OpenChannelFee(
        new OpenChannelFeeRequest(amountMsat));
}
catch (Exception)
{
    // Handle error
}
1

For more details on these fees, see Channel Opening Fees