Connecting to an LSP
Getting the current LSP Information
Based on the API key provided to the Breez SDK, a default LSP is selected for your node to provide liquidity to it. To get the information about the selected LSP you can do the following:
let lsp_id = sdk.lsp_id().await?;
let lsp_info = sdk.lsp_info().await?;
let lspId = try? sdk.lspId()
let lspInfo = try? sdk.lspInfo()
try {
val lspId = sdk.lspId()
if (lspId != null) {
val lspInfo = sdk.lspInfo()
} else {
// Handle no lsp id scenario
}
} catch (e: Exception) {
// Handle error
}
try {
const id = await lspId()
const info = await lspInfo()
} catch (err) {
console.error(err)
}
String? lspId = await breezSDK.lspId();
LspInformation? lspInfo = await breezSDK.lspInfo();
print(lspId);
print(lspInfo);
lsp_id = sdk_services.lsp_id()
lsp_info = sdk_services.lsp_info()
if lspId, err := sdk.LspId(); lspId != nil && err == nil {
log.Printf("%#v", *lspId)
}
if lspInfo, err := sdk.LspInfo(); err == nil {
log.Printf("%#v", lspInfo)
}
try
{
var lspId = sdk.LspId();
var lspInfo = sdk.LspInfo();
}
catch (Exception)
{
// Handle error
}
Listing available LSPs
In order to list all available LSPs you may connect to, you may do the following:
let available_lsps = sdk.list_lsps().await?;
let availableLsps = try? sdk.listLsps()
try {
val availableLsps = sdk.listLsps()
} catch (e: Exception) {
// Handle error
}
try {
const availableLsps = await listLsps()
} catch (err) {
console.error(err)
}
List<LspInformation> availableLsps = await breezSDK.listLsps();
available_lsps = sdk_services.list_lsps()
if lspList, err := sdk.ListLsps(); err == nil {
log.Printf("%#v", lspList)
}
try
{
var availableLsps = sdk.ListLsps();
}
catch (Exception)
{
// Handle error
}
Switching to another LSP
When you have selected an LSP you may then connect to it:
sdk.connect_lsp(lsp_id).await?;
try? sdk.connectLsp(lspId: lspId)
try {
sdk.connectLsp(lspId)
} catch (e: Exception) {
// Handle error
}
try {
const id = 'your selected lsp id'
await connectLsp(id)
} catch (err) {
console.error(err)
}
await breezSDK.connectLSP(lspId);
sdk_services.connect_lsp(lsp_id)
lspId := "your selected lsp id"
if err := sdk.ConnectLsp(lspId); err != nil {
log.Printf("%#v", err)
}
try
{
sdk.ConnectLsp(lspId!);
}
catch (Exception)
{
// Handle error
}
Channel Opening Fees
Some Breez SDK operations1 may need opening a new channel with the LSP. The SDK supports the LSP2 dynamic fees spec2, which describes how these channel opening fees are handled.
For the client, the key points are:
- The
LspInformation
can be fetched at any point and includes a list of channel opening fees and the duration for which they are valid. The fees are sorted from cheapest to most expensive. The higher fees are typically also valid for longer. - Depending on the application and use-case, the client may choose an appropriate fee and give it as an argument in the relevant Breez SDK method. If this fee argument is not provided, Breez SDK will choose an appropriate one instead.
The channel opening fees are provided in a structure3 that includes the conditions associated with these fees, like the minimum invoice amount or the date and time until when this opening fee is valid.
See the service methods receive_payment
, receive_onchain
or buy_bitcoin
.
https://github.com/BitcoinAndLightningLayerSpecs/lsp/tree/main/LSPS2
https://breez.github.io/breez-sdk/breez_sdk_core/struct.OpeningFeeParams.html