LNURL-Withdraw

Usage

Rust
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
let lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";

if let Ok(LnUrlWithdraw { data: wd }) = parse(lnurl_withdraw_url).await {
    let amount_msat = wd.min_withdrawable;
    let description = "Test withdraw".to_string();

    sdk.lnurl_withdraw(LnUrlWithdrawRequest {
        data: wd,
        amount_msat,
        description: Some(description),
    })
    .await?;
}
Swift
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
var response: LnUrlWithdrawResult?
let lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"

if let inputType = try? parseInput(s: lnurlWithdrawUrl) {
    if case let .lnUrlWithdraw(data) = inputType {
        let amountMsat = data.maxWithdrawable
        let description = "Test withdraw"
        response = try? sdk.withdrawLnurl(
            request: LnUrlWithdrawRequest(
                data: data,
                amountMsat: amountMsat,
                description: description
            )
        )
    }
}
Kotlin
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
val lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7..."
try {
    val inputType = parseInput(lnurlWithdrawUrl)
    if (inputType is InputType.LnUrlWithdraw) {
        val requestData = inputType.data
        val amountMsat = requestData.minWithdrawable
        val comment = "Any comment"
        sdk.withdrawLnurl(LnUrlWithdrawRequest(requestData, amountMsat, comment))
    }
} catch (e: Exception) {
    // handle error
}
React Native
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
try {
  const lnurlWithdrawUrl =
        'lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk'

  const input = await parseInput(lnurlWithdrawUrl)
  if (input.type === InputTypeVariant.LN_URL_WITHDRAW) {
    const amountMsat = input.data.minWithdrawable
    const lnUrlWithdrawResult = await withdrawLnurl({
      data: input.data,
      amountMsat,
      description: 'comment'
    })
  }
} catch (err) {
  console.error(err)
}
Dart
/// Endpoint can also be of the form:
/// lnurlw://domain.com/lnurl-withdraw?key=val
String lnurlWithdrawUrl =
    "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";

InputType inputType = await breezSDK.parseInput(input: lnurlWithdrawUrl);
if (inputType is InputType_LnUrlWithdraw) {
  int amountMsat = inputType.data.minWithdrawable;
  LnUrlWithdrawRequest req = LnUrlWithdrawRequest(
    data: inputType.data,
    amountMsat: amountMsat,
    description: "<description>",
  );
  LnUrlWithdrawResult result = await breezSDK.lnurlWithdraw(req: req);
  print(result.data);
}
Python
# Endpoint can also be of the form:
# lnurlw://domain.com/lnurl-withdraw?key=val
lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"

try:
    parsed_input = breez_sdk.parse_input(lnurl_withdraw_url)
    if isinstance(parsed_input, breez_sdk.InputType.LN_URL_WITHDRAW):
        amount_msat = parsed_input.data.min_withdrawable
    result = sdk_services.withdraw_lnurl(parsed_input.data, amount_msat, "comment")
    return result
except Exception as error:
    print(error)
    raise
Go
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
lnurlWithdrawUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"

if input, err := breez_sdk.ParseInput(lnurlWithdrawUrl); err != nil {
    switch inputType := input.(type) {
    case breez_sdk.InputTypeLnUrlWithdraw:
        amountMsat := inputType.Data.MinWithdrawable
        description := "comment"
        if result, err := sdk.WithdrawLnurl(breez_sdk.LnUrlWithdrawRequest{
            Data:        inputType.Data,
            AmountMsat:  amountMsat,
            Description: &description,
        }); err != nil {
            switch result.(type) {
            case breez_sdk.LnUrlCallbackStatusOk:
                log.Printf("Successfully withdrawn")
            default:
                log.Printf("Failed to withdraw")
            }
        }
    }
}
C#
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
var lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";

try
{
    var input = BreezSdkMethods.ParseInput(lnurlWithdrawUrl);
    if (input is InputType.LnUrlWithdraw lnurlw)
    {
        var amountMsat = lnurlw.data.minWithdrawable;
        var result = sdk.WithdrawLnurl(
            new LnUrlWithdrawRequest(
                lnurlw.data,
                amountMsat,
                "comment"));
    }
}
catch (Exception)
{
    // Handle error
}

Supported Specs

  • LUD-01 LNURL bech32 encoding
  • LUD-03 withdrawRequest spec
  • LUD-17 Support for lnurlw prefix with non-bech32-encoded LNURL URLs