Connecting
The first step is to construct the SDK configuration. Among others, it sets the network you want to use, the SDK working directory and the Breez API key.
The SDK uses the config working_dir
to store the state of the SDK instance. When handling multiple instances of the SDK, each instance needs to have a different working directory defined.
Now you are ready to interact with the SDK.
let mnemonic = Mnemonic::generate_in(Language::English, 12)?;
// Create the default config, providing your Breez API key
let mut config = LiquidSdk::default_config(LiquidNetwork::Mainnet, Some("<your-Breez-API-key>".to_string()))?;
// 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 = LiquidSdk::connect(connect_request).await?;
let mnemonic = "<mnemonic words>"
// Create the default config, providing your Breez API key
var config = try defaultConfig(network: LiquidNetwork.mainnet, breezApiKey: "<your-Breez-API-key>")
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
let connectRequest = ConnectRequest(config: config, mnemonic: mnemonic)
let sdk = try? connect(req: connectRequest)
val mnemonic = "<mnemonic words>"
// Create the default config, providing your Breez API key
val config : Config = defaultConfig(LiquidNetwork.MAINNET, "<your Breez API key>")
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
try {
val connectRequest = ConnectRequest(config, mnemonic)
val sdk = connect(connectRequest)
} catch (e: Exception) {
// handle error
}
const mnemonic = '<mnemonics words>'
// Create the default config, providing your Breez API key
const config = await defaultConfig(
LiquidNetwork.MAINNET,
'<your-Breez-API-key>'
)
// By default in React Native the workingDir is set to:
// `/<APPLICATION_SANDBOX_DIRECTORY>/breezSdkLiquid`
// You can change this to another writable directory or a
// subdirectory of the workingDir if managing multiple mnemonics.
console.log(`Working directory: ${config.workingDir}`)
// config.workingDir = "path to writable directory"
await connect({ mnemonic, config })
// It is recommended to use a single instance of BreezSDKLiquid across your Dart/Flutter app.
//
// All of the snippets assume a BreezSDKLiquid object is created on entrypoint of the app as such:
//
// ConnectRequest req = ConnectRequest(...);
// BindingLiquidSdk instance = await connect(req: req);
//
// and is accessible throughout the app. There are various approaches on how to achieve this:
// creating a Singleton class using factory constructor, using state management libraries such as 'provider', 'GetX',
// 'Riverpod' and 'Redux' to name a few.
//
// The Dart snippets included here rely on the example approach seen on sdk_instance.dart to manage wallet connection
// and Liquid SDK streams. This approach also has essential helper methods to ensure wallet data is in sync.
// Please see sdk_instance.dart for more details:
// [sdk_instance.dart](https://github.com/breez/breez-sdk-liquid-docs/blob/main/snippets/dart_snippets/lib/sdk_instance.dart)
// Create the default config
String mnemonic = "<mnemonic words>";
// Create the default config, providing your Breez API key
Config config = defaultConfig(
network: LiquidNetwork.mainnet,
breezApiKey: "<your-Breez-API-key>"
);
// Customize the config object according to your needs
config = config.copyWith(workingDir: "path to an existing directory");
ConnectRequest connectRequest = ConnectRequest(mnemonic: mnemonic, config: config);
await breezSDKLiquid.connect(req: connectRequest);
mnemonic = "<mnemonic words>"
# Create the default config, providing your Breez API key
config = default_config(network=LiquidNetwork.MAINNET, breez_api_key="<your-Breez-API-key>")
# Customize the config object according to your needs
config.working_dir = "path to an existing directory"
try:
connect_request = ConnectRequest(config, mnemonic)
sdk = connect(connect_request)
return sdk
except Exception as error:
logging.error(error)
raise
mnemonic := "<mnemonic words>"
// Create the default config, providing your Breez API key
breezApiKey := "<your-Breez-API-key>"
config, err := breez_sdk_liquid.DefaultConfig(breez_sdk_liquid.LiquidNetworkMainnet, &breezApiKey)
if err != nil {
return nil, err
}
// Customize the config object according to your needs
config.WorkingDir = "path to an existing directory"
connectRequest := breez_sdk_liquid.ConnectRequest{
Config: config,
Mnemonic: mnemonic,
}
sdk, err := breez_sdk_liquid.Connect(connectRequest)
return sdk, err
var mnemonic = "<mnemonic words>";
// Create the default config, providing your Breez API key
var config = BreezSdkLiquidMethods.DefaultConfig(
LiquidNetwork.Mainnet,
"<your-Breez-API-key>"
) with
{
// Customize the config object according to your needs
workingDir = "path to an existing directory"
};
try
{
var connectRequest = new ConnectRequest(config, mnemonic);
var sdk = BreezSdkLiquidMethods.Connect(connectRequest);
}
catch (Exception)
{
// Handle error
}
Developer note
By default, the config working directory is set to the directory where the SDK is running. Some platforms may require that you use an application specific directory that is writable within the application sandbox. For example applications running on Android or iOS.
Disconnecting
Once you are done using the SDK, you can call the disconnect
method to free up the resources which are currently in use.
This is especially useful in cases where the SDK has to be re-instantiated, for example when you need to change the mnemonic and/or configuration.
async fn disconnect(
sdk: Arc<LiquidSdk>,
) -> Result<()> {
sdk.disconnect().await?;
Ok(())
}
func disconnect(sdk: BindingLiquidSdk) throws {
try? sdk.disconnect()
}
fun disconnect(sdk: BindingLiquidSdk) {
try {
sdk.disconnect()
} catch (e: Exception) {
// handle error
}
}
await disconnect()
void disconnect() {
breezSDKLiquid.disconnect();
}
def disconnect(sdk: BindingLiquidSdk):
try:
sdk.disconnect()
except Exception as error:
logging.error(error)
raise
func Disconnect(sdk *breez_sdk_liquid.BindingLiquidSdk) {
sdk.Disconnect()
}
public void Disconnect(BindingLiquidSdk sdk)
{
try
{
sdk.Disconnect();
}
catch (Exception)
{
// Handle error
}
}