Connecting
The first step is to construct the SDK configuration. Among others, it sets the network you want to use and the SDK working directory.
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.
Rust
let mnemonic = Mnemonic::generate_in(Language::English, 12)?;
// Create the default config
let mut config = 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 = LiquidSdk::connect(connect_request).await?;
Swift
let mnemonic = "<mnemonic words>"
// Create the default config
var config = defaultConfig(network: LiquidNetwork.mainnet)
// 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)
Kotlin
val mnemonic = "<mnemonic words>"
// Create the default config
val config : Config = defaultConfig(LiquidNetwork.MAINNET)
// 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
}
React Native
const mnemonic = '<mnemonics words>'
// Create the default config
const config = await defaultConfig(
LiquidNetwork.MAINNET
)
// 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 })
Dart
// 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
Config config = defaultConfig(
network: LiquidNetwork.mainnet,
);
// 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);
Python
mnemonic = "<mnemonic words>"
# Create the default config
config = default_config(LiquidNetwork.MAINNET)
# 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
Go
mnemonic := "<mnemonic words>"
// Create the default config
config := breez_sdk_liquid.DefaultConfig(breez_sdk_liquid.LiquidNetworkMainnet)
// 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
C#
var mnemonic = "<mnemonic words>";
// Create the default config
var config = BreezSdkLiquidMethods.DefaultConfig(
LiquidNetwork.Mainnet
) 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 ./.data
. 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.