Sending spontaneous Lightning payments

They can even be spontaneous payments to a node without a bolt11 invoice.

Rust
let node_id = "...".into();
let optional_label = Some("<label>".to_string());

sdk.send_spontaneous_payment(SendSpontaneousPaymentRequest {
    amount_msat: 3_000_000,
    node_id,
    extra_tlvs: None,
    label: optional_label,
})
.await?;
Swift
let optionalLabel = "<label>"
let req = SendSpontaneousPaymentRequest(nodeId: "...", amountMsat: 3_000_000, label: optionalLabel)
let response = try? sdk.sendSpontaneousPayment(req: req)
Kotlin
val nodeId = "..."
val amountMsat = 3_000_000.toULong()
val optionalLabel = "<label>"
try {
    val req = SendSpontaneousPaymentRequest(nodeId, amountMsat, label = optionalLabel)
    val response = sdk.sendSpontaneousPayment(req)
} catch (e: Exception) {
    // handle error
}
React Native
try {
  const nodeId = '...'
  const optionalLabel = '<label>'

  const sendPaymentResponse = await sendSpontaneousPayment({
    nodeId,
    amountMsat: 3000000,
    label: optionalLabel
  })
} catch (err) {
  console.error(err)
}
Dart
String optionalLabel = "<label>";

SendSpontaneousPaymentRequest req = SendSpontaneousPaymentRequest(
  amountMsat: 3000000,
  nodeId: nodeId,
  label: optionalLabel,
);
SendPaymentResponse resp = await breezSDK.sendSpontaneousPayment(req: req);
Python
node_id = "..."
amount_msat = 3000000
optional_label = "<label>"
try:
    req = breez_sdk.SendSpontaneousPaymentRequest(node_id, amount_msat, label=optional_label)
    result = sdk_services.send_spontaneous_payment(req)
    return result
except Exception as error:
    print(error)
    raise
Go
optionalLabel := "<label>"
sendSpontaneousPaymentRequest := breez_sdk.SendSpontaneousPaymentRequest{
    NodeId:     "...",
    AmountMsat: uint64(3_000_000),
    Label:      &optionalLabel,
}
if response, err := sdk.SendSpontaneousPayment(sendSpontaneousPaymentRequest); err == nil {
    log.Printf("%#v", response)
}
C#
var nodeId = "...";
ulong amountMsat = 3_000_000;
var optionalLabel = "<label>";

try
{
    var response = sdk.SendSpontaneousPayment(
        new SendSpontaneousPaymentRequest(nodeId, amountMsat, label: optionalLabel));
}
catch (Exception)
{
    // Handle error
}

Adding Extra TLVs to a Spontaneous Payment

A list of extra TLV data can also be sent with the spontaneous payment.

Rust
let node_id = "...".into();
let optional_extra_tlvs = Some(vec![TlvEntry {
    field_number: 34349334,
    value: "Hello world!".as_bytes().to_vec(),
}]);

sdk.send_spontaneous_payment(SendSpontaneousPaymentRequest {
    amount_msat: 3_000_000,
    node_id,
    extra_tlvs: optional_extra_tlvs,
    label: None,
})
.await?;
Swift
let optionalExtraTlvs = [TlvEntry(fieldNumber: 34_349_334, value: Array("Hello world!".utf8))]
let req = SendSpontaneousPaymentRequest(nodeId: "...", amountMsat: 3_000_000, extraTlvs: optionalExtraTlvs)
let response = try? sdk.sendSpontaneousPayment(req: req)
Kotlin
val nodeId = "..."
val amountMsat = 3_000_000.toULong()
val optionalExtraTlvs = listOf<TlvEntry>(
    TlvEntry(34_349_334.toULong(), "Hello world!".encodeToByteArray().asUByteArray().toList())
)
try {
    val req = SendSpontaneousPaymentRequest(nodeId, amountMsat, optionalExtraTlvs)
    val response = sdk.sendSpontaneousPayment(req)
} catch (e: Exception) {
    // handle error
}
React Native
try {
  const nodeId = '...'
  const optionalExtraTlvs: TlvEntry[] = [
    { fieldNumber: 34349334, value: stringToBytes('Hello world!') }
  ]

  const sendPaymentResponse = await sendSpontaneousPayment({
    nodeId,
    amountMsat: 3000000,
    extraTlvs: optionalExtraTlvs
  })
} catch (err) {
  console.error(err)
}
Dart
List<TlvEntry> optionalExtraTlvs = [
  TlvEntry(
    fieldNumber: 34349334,
    value: utf8.encode("Hello world!"),
  )
];
SendSpontaneousPaymentRequest req = SendSpontaneousPaymentRequest(
  amountMsat: 3000000,
  nodeId: nodeId,
  extraTlvs: optionalExtraTlvs,
);
SendPaymentResponse resp = await breezSDK.sendSpontaneousPayment(req: req);
Python
node_id = "..."
amount_msat = 300000
optional_extra_tlvs = [breez_sdk.TlvEntry(34349334, str.encode("Hello world!"))]
try:
    req = breez_sdk.SendSpontaneousPaymentRequest(node_id, amount_msat, optional_extra_tlvs)
    result = sdk_services.send_spontaneous_payment(req)
    return result
except Exception as error:
    print(error)
    raise        
Go
value, _ := hex.DecodeString("Hello world!")
optionalExtraTlvs := []breez_sdk.TlvEntry{
    breez_sdk.TlvEntry{
        FieldNumber: uint64(34349334),
        Value:       value,
    },
}
sendSpontaneousPaymentRequest := breez_sdk.SendSpontaneousPaymentRequest{
    NodeId:     "...",
    AmountMsat: uint64(3_000_000),
    ExtraTlvs:  &optionalExtraTlvs,
}
if response, err := sdk.SendSpontaneousPayment(sendSpontaneousPaymentRequest); err == nil {
    log.Printf("%#v", response)
}
C#
var nodeId = "...";
ulong amountMsat = 3_000_000;
var optionalExtraTlvs = new List<TlvEntry>{
    new TlvEntry(34349334, Encoding.ASCII.GetBytes("Hello world!").ToList())
};

try
{
    var response = sdk.SendSpontaneousPayment(
        new SendSpontaneousPaymentRequest(nodeId, amountMsat, optionalExtraTlvs));
}
catch (Exception)
{
    // Handle error
}