Crate breez_sdk_liquid

source ·
Expand description

§Breez SDK - Liquid

This SDK provides developers with an end-to-end solution for integrating self-custodial Lightning payments into their apps and services. It eliminates the need for third-parties, simplifies the complexities of Bitcoin and Lightning, and enables seamless onboarding for billions of users to the future of peer-to-peer payments.

The Liquid implementation is a nodeless Lightning integration. It offers a self-custodial, end-to-end solution for integrating Lightning payments, utilizing the Liquid Network with on-chain interoperability and third-party fiat on-ramps.

  • Sending payments (via protocols such as: bolt11, lnurl-pay, lightning address, btc address)
  • Receiving payments (via protocols such as: bolt11, lnurl-withdraw, btc address)
  • Interacting with a wallet (e.g. balance, max allow to pay, max allow to receive, on-chain balance)

§Getting Started

The following code initialize the SDK and make it ready to be used:

let mnemonic = Mnemonic::generate_in(Language::English, 12)?;

// Create the default config
let mut config = sdk::LiquidSdk::default_config(LiquidNetwork::Mainnet);

// Customize the config object according to your needs
config.working_dir = "path to an existing directory".into();

let connect_request = ConnectRequest {
    mnemonic: mnemonic.to_string(),
    config,
};
let sdk = sdk::LiquidSdk::connect(connect_request).await?;

We can now receive payments

// Fetch the Receive limits
let current_limits = sdk.fetch_lightning_limits().await?;
info!("Minimum amount: {} sats", current_limits.receive.min_sat);
info!("Maximum amount: {} sats", current_limits.receive.max_sat);

// Set the amount you wish the payer to send, which should be within the above limits
let prepare_receive_response = sdk
    .prepare_receive_payment(&PrepareReceiveRequest {
        payment_method: PaymentMethod::Lightning,
        payer_amount_sat: Some(5_000),
    })
    .await?;

// If the fees are acceptable, continue to create the Receive Payment
let receive_fees_sat = prepare_receive_response.fees_sat;

let receive_payment_response = sdk.receive_payment(&ReceivePaymentRequest {
    description: Some("my description".to_string()),
    prepare_response: receive_payment_response,
}).await?;

let destination = receive_payment_response.destination;

or make payments

// Set the BOLT11 invoice or Liquid BIP21/address you wish to pay
let prepare_send_response = sdk
    .prepare_send_payment(&PrepareSendRequest {
        destination: "invoice or Liquid BIP21/address".to_string(),
        amount_sat: Some(3_000),
    })
    .await?;

// If the fees are acceptable, continue to create the Send Payment
let send_fees_sat = prepare_send_response.fees_sat;

let send_response = sdk.send_payment(&SendPayentRequest {
    prepare_response: prepare_send_response,
}).await?;
let payment = send_response.payment;

At any point we can fetch the wallet state

let wallet_info = sdk.get_info().await?;
let balance_sat = wallet_info.balance_sat;
let pending_send_sat = wallet_info.pending_send_sat;
let pending_receive_sat = wallet_info.pending_receive_sat;

or fetch other useful infos, like the current mempool model::RecommendedFees

let fees = sdk.recommended_fees().await?;

These different types of operations are described below in more detail.

§Initializing the SDK

There are two simple steps necessary to initialize the SDK:

  1. sdk::LiquidSdk::default_config to construct the SDK model::Config
  2. sdk::LiquidSdk::connect to initialize the sdk::LiquidSdk instance

Although you can create your own config from scratch it is recommended to use the sdk::LiquidSdk::default_config method and customize it according to your needs. Once the model::Config is created it is passed to the sdk::LiquidSdk::connect method along with the mnemonic.

Now your SDK is ready to be used.

§Sending a Lightning payment

§Receiving a Lightning/onchain payment

§Sending an onchain payment

§Refunding a payment

§Using LNURL

§Supporting fiat currencies

§Utilities

§Bindings

  • Dart
  • Flutter
  • Kotlin
  • Python
  • React-Native
  • Swift

§Support

Join this telegram group.

Modules§

Macros§

Structs§

Enums§

Statics§

Traits§

Functions§

Type Aliases§