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:

Rust
let lsp_id = sdk.lsp_id().await?;
let lsp_info = sdk.lsp_info().await?;
Swift
let lspId = try? sdk.lspId()
let lspInfo = try? sdk.lspInfo()
Kotlin
try {
    val lspId = sdk.lspId()
    if (lspId != null) {
        val lspInfo = sdk.lspInfo()
    } else {
        // Handle no lsp id scenario
    }
} catch (e: Exception) {
    // Handle error
}
React Native
try {
  const id = await lspId()
  const info = await lspInfo()
} catch (err) {
  console.error(err)
}
Dart
String? lspId = await BreezSDK().lspId();
LspInformation? lspInfo = await BreezSDK().lspInfo();
print(lspId);
print(lspInfo);
Python
lsp_id = sdk_services.lsp_id()
lsp_info = sdk_services.lsp_info()
Go
if lspId, err := sdk.LspId(); lspId != nil && err == nil {
    log.Printf("%#v", *lspId)
}

if lspInfo, err := sdk.LspInfo(); err == nil {
    log.Printf("%#v", lspInfo)
}
C#
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:

Rust
let available_lsps = sdk.list_lsps().await?;
Swift
let availableLsps = try? sdk.listLsps()
Kotlin
try {
    val availableLsps = sdk.listLsps()
} catch (e: Exception) {
    // Handle error
}
React Native
try {
  const availableLsps = await listLsps()
} catch (err) {
  console.error(err)
}
Dart
List<LspInformation> availableLsps = await BreezSDK().listLsps();
Python
available_lsps = sdk_services.list_lsps()
Go
if lspList, err := sdk.ListLsps(); err == nil {
    log.Printf("%#v", lspList)
}
C#
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:

Rust
sdk.connect_lsp(lsp_id).await?;
Swift
try? sdk.connectLsp(lspId: lspId)
Kotlin
try {
    sdk.connectLsp(lspId)
} catch (e: Exception) {
    // Handle error
}
React Native
try {
  const id = 'your selected lsp id'
  await connectLsp(id)
} catch (err) {
  console.error(err)
}
Dart
await BreezSDK().connectLSP(lspId);
Python
sdk_services.connect_lsp(lsp_id)
Go
lspId := "your selected lsp id"

if err := sdk.ConnectLsp(lspId); err != nil {
    log.Printf("%#v", err)
}
C#
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.


1

See the service methods receive_payment, receive_onchain or buy_bitcoin.