Files
breez-sdk-docs/src/guide/payments.md
2023-09-02 11:35:19 +02:00

5.2 KiB

Sending and receiving Lightning payments

Receiving Lightning Payments

Breez SDK doesn't require you to open a channel and set up your inbound liquidity. Breez SDK automatically connects your node to the LSP peer and you can now receive payments:

Rust
let invoice = sdk.receive_payment(3000, "Invoice for 3000 sats".into()).await?;
Swift
let reqData = ReceivePaymentRequest(amountSats: 3000, description: "Invoice for 3000 sats")
do {
  let invoice = try sdk.receivePayment(reqData: reqData )
} catch {
    // handle error
}
Android
try {
    val invoice = sdk.receivePayment(3000L.toULong(), "Invoice for 3000 sats")
} catch (e: Exception) {
    // handle error
}
React Native
try {
    const invoice = await receivePayment(3000, "Invoice for 3000 sats")
} catch (error) {
    console.log(error)
}
Dart
try {
    ReceivePaymentRequestData requestData = ReceivePaymentRequestData(amountSats: 3000, description: "Invoice for 3000 sats");
    ReceivePaymentResponse invoice = await receivePayment(reqData: requestData);
} catch (error) {
    // handle error
}
Python
try:
  req_data = breez_sdk.ReceivePaymentRequest(amount_sats=3000, description="Invoice for 3000 sats")
  receive_payment_response = sdk_services.receive_payment(req_data=req_data)
except Exception as error:
  # Handle error
Go
invoice, err := sdkServices.ReceivePayment(3000, "Invoice for 3000 sats")
C#
try 
{
    var invoice = sdk.ReceivePayment(3000, "Invoice for 3000 sats");
} 
catch (Exception) 
{
    // Handle error
}

Sending Lightning Payments

Rust
let bolt11 = "...";
sdk.send_payment(bolt11.into(), Some(3000)).await?;
Swift
let bolt11 = "...";
do {
  // The `amountSats` param is optional so nil can be passed if the 
  // bolt11 invoice spesifies an amount.
  let payment = try sdk.sendPayment(bolt11:  bolt11, amountSats: 3000)
} catch {
    // handle error
}
Android
val bolt11 = "..."
try {
    val payment = sdk.sendPayment(bolt11, 3000L.toULong())
} catch (e: Exception) {
    // handle error
}
React Native
const bolt11 = "...";
try {
    const payment = await sendPayment(bolt11, 3000)
} catch (error) {
    console.log(error)
}
Dart
String bolt11 = "...";
try {
    Payment payment = await sendPayment(
      bolt11: bolt11,
      amountSats: 3000,
    );
} catch (error) {
    // handle error
}
Python
bolt11 = "..."
try:
  sdk_services.send_payment(bolt11=bolt11, amount_sats=3000)
except Exception as error:
  # Handle error
Go
const bolt11 = "...";
payment, err := sdkServices.SendPayment(bolt11, 3000)
C#
const bolt11 = "...";
try 
{
    var payment = sdk.SendPayment(bolt11, 3000);
} 
catch (Exception) 
{
    // Handle error
}

Sending Spontaneous Lightning Payments

Rust
let node_id = "...";
sdk.send_spontaneous_payment(node_id.into(), 3000).await?;
Swift
let nodeId = "...";
do {
  let payment = try sdk.sendSpontaneousPayment(nodeId: nodeId, amountSats: 3000)
} catch {
    // handle error
}
Android
val nodeId = "..."
try {
    val payment = sdk.sendSpontaneousPayment(nodeId, 3000L.toULong())
} catch (e: Exception) {
    // handle error
}
React Native
const nodeId = "...";
try {
    const payment = await sendSpontaneousPayment(nodeId, 3000)
} catch (error) {
    console.log(error)
}
Dart
String nodeId = "...";
try {
    Payment payment = await sendSpontaneousPayment(
      nodeId: nodeId,
      amountSats: 3000,
    );
} catch (error) {
    // handle error
}
Python
node_id = "..."
try:
  sdk_services.send_spontaneous_payment(node_id=node_id, amount_sats=3000)
except Exception as error:
  # Handle error
Go
const nodeId = "...";
payment, err := sdkServices.SendSpontaneousPayment(nodeId, 3000)
C#
const nodeId = "...";
try 
{
    var payment = sdk.SendSpontaneousPayment(nodeId, 3000);
} 
catch (Exception) 
{
    // Handle error
}