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(InputType::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? parse(input: lnurlWithdrawUrl){
if case.lnUrlWithdraw(let `data`) = inputType {
let amountMsat = data.maxWithdrawable
let description = "Test withdraw"
response = try? sdk.lnurlWithdraw(req: 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 = parse(lnurlWithdrawUrl)
if (inputType is InputType.LnUrlWithdraw) {
val requestData = inputType.data
val amountMsat = requestData.minWithdrawable
val comment = "Any comment"
sdk.lnurlWithdraw(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
const lnurlWithdrawUrl =
'lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk'
const input = await parse(lnurlWithdrawUrl)
if (input.type === InputTypeVariant.LN_URL_WITHDRAW) {
const amountMsat = input.data.minWithdrawable
const lnUrlWithdrawResult = await lnurlWithdraw({
data: input.data,
amountMsat,
description: 'comment'
})
}
Dart
/// Endpoint can also be of the form:
/// lnurlw://domain.com/lnurl-withdraw?key=val
String lnurlWithdrawUrl =
"lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
InputType inputType = await parse(input: lnurlWithdrawUrl);
if (inputType is InputType_LnUrlWithdraw) {
BigInt amountMsat = inputType.data.minWithdrawable;
LnUrlWithdrawRequest req = LnUrlWithdrawRequest(
data: inputType.data,
amountMsat: amountMsat,
description: "<description>",
);
LnUrlWithdrawResult result = await breezSDKLiquid.instance!.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_liquid.parse(lnurl_withdraw_url)
if isinstance(parsed_input, InputType.LN_URL_WITHDRAW):
amount_msat = parsed_input.data.min_withdrawable
result = sdk.lnurl_withdraw(parsed_input.data, amount_msat, "comment")
return result
except Exception as error:
logging.error(error)
raise
Go
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
lnurlWithdrawUrl := "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
if input, err := breez_sdk_liquid.Parse(lnurlWithdrawUrl); err != nil {
switch inputType := input.(type) {
case breez_sdk_liquid.InputTypeLnUrlWithdraw:
amountMsat := inputType.Data.MinWithdrawable
description := "comment"
if result, err := sdk.LnurlWithdraw(breez_sdk_liquid.LnUrlWithdrawRequest{
Data: inputType.Data,
AmountMsat: amountMsat,
Description: &description,
}); err != nil {
switch result.(type) {
case breez_sdk_liquid.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 = BreezSdkLiquidMethods.Parse(lnurlWithdrawUrl);
if (input is InputType.LnUrlWithdraw lnurlw)
{
var amountMsat = lnurlw.data.minWithdrawable;
var result = sdk.LnurlWithdraw(
new LnUrlWithdrawRequest(
lnurlw.data,
amountMsat,
"comment"));
}
}
catch (Exception)
{
// Handle error
}