mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-19 06:44:19 +01:00
change getting_started to use connect api
This commit is contained in:
@@ -9,7 +9,7 @@ The Breez SDK provides the following services:
|
|||||||
* Fetching node status (e.g. balance, max allow to pay, max allow to receive, on-chain balance, etc.)
|
* Fetching node status (e.g. balance, max allow to pay, max allow to receive, on-chain balance, etc.)
|
||||||
* Connecting to a new or existing node.
|
* Connecting to a new or existing node.
|
||||||
|
|
||||||
Connecting to a node requires a seed (your master key) and credentials. The seed is a bip39 mnemonic and the credentials are retrieved by registering a new node or recovering an existing one.
|
Connecting to a node requires a seed (your master key). The seed is a bip39 mnemonic.
|
||||||
|
|
||||||
## Installing
|
## Installing
|
||||||
|
|
||||||
@@ -19,44 +19,30 @@ Breez SDK is available in several platforms. Follow the [Installing](install.md)
|
|||||||
<div slot="title">Rust</div>
|
<div slot="title">Rust</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
The first step is to register a new node. In order to do that a seed is needed.
|
## Connecting
|
||||||
## Registering a new node
|
|
||||||
```rust,no_run
|
|
||||||
let seed = <your seed>;
|
|
||||||
let invite_code = <your greenlight invite code>;
|
|
||||||
|
|
||||||
// register_node takes either greenlight credentials (certifate & key) or invite code.
|
|
||||||
// At this example we are using the invite code option.
|
|
||||||
let credentials = BreezServices::register_node(Network::Bitcoin, seed, None, Some(invite_code)).await?;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recovering an existing node
|
|
||||||
```rust,no_run
|
|
||||||
let seed = <your seed>;
|
|
||||||
let credentials = BreezServices::recover_node(Network::Bitcoin, seed).await?;
|
|
||||||
```
|
|
||||||
|
|
||||||
Once the credentials are retrieved they should be saved in a secured storage.
|
|
||||||
The next step is to initialize the SDK and start the node:
|
|
||||||
|
|
||||||
## Initializing the SDK
|
|
||||||
```rust,no_run
|
```rust,no_run
|
||||||
// Create the default config
|
// Create the default config
|
||||||
let mut config = BreezServices::default_config(EnvironmentType::Production);
|
let config = BreezServices::default_config(
|
||||||
|
EnvironmentType::Production,
|
||||||
|
"your API key".into(),
|
||||||
|
breez_sdk_core::NodeConfig::Greenlight {
|
||||||
|
config: GreenlightNodeConfig {
|
||||||
|
partner_credentials: None,
|
||||||
|
invite_code: None,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Customize the config object according to your needs
|
// Customize the config object according to your needs
|
||||||
config.api_key = Some("your API key".into());
|
|
||||||
config.working_dir = "path to an existing directory".into();
|
config.working_dir = "path to an existing directory".into();
|
||||||
|
|
||||||
let sdk = BreezServices::init_services(
|
// Connect to the Breez SDK make it ready for use
|
||||||
|
let sdk = BreezServices::connect(
|
||||||
config,
|
config,
|
||||||
seed.to_vec(),
|
seed.to_vec(),
|
||||||
credentials.clone(),
|
|
||||||
Box::new(AppEventListener {}),
|
Box::new(AppEventListener {}),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
BreezServices::start(rt(), &sdk).await?;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
At any point we can fetch our balance from the Greenlight node:
|
At any point we can fetch our balance from the Greenlight node:
|
||||||
@@ -71,35 +57,7 @@ if let Some(node_state) = sdk.node_info()? {
|
|||||||
<div slot="title">Swift</div>
|
<div slot="title">Swift</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
The first step is to register a new node. In order to do that a seed is needed.
|
## Connecting
|
||||||
## Registering a new node
|
|
||||||
```swift
|
|
||||||
do {
|
|
||||||
let seed = try mnemonicToSeed(phrase: "<mnemonics words>")
|
|
||||||
let inviteCode = ""
|
|
||||||
|
|
||||||
// register_node takes either greenlight credentials (certifate & key) or invite code.
|
|
||||||
// At this example we are using the invite code option.
|
|
||||||
let credentials = try registerNode(network: Network.bitcoin, seed: seed, registerCredentials: nil, inviteCode: inviteCode)
|
|
||||||
} catch {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recovering an existing node
|
|
||||||
```swift
|
|
||||||
do {
|
|
||||||
let seed = try mnemonicToSeed(phrase: "<mnemonics words>")
|
|
||||||
let credentials = try recoverNode(network: Network.bitcoin, seed: seed)
|
|
||||||
} catch {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Once the credentials are retrieved they should be saved in a secured storage.
|
|
||||||
The next step is to initialize the SDK and start the node:
|
|
||||||
|
|
||||||
## Initializing the SDK
|
|
||||||
```swift
|
```swift
|
||||||
|
|
||||||
// SDK events listener
|
// SDK events listener
|
||||||
@@ -110,15 +68,18 @@ class SDKListener: EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the default config
|
// Create the default config
|
||||||
var config = defaultConfig(envType: EnvironmentType.production)
|
let seed = try mnemonicToSeed(phrase: "<mnemonics words>")
|
||||||
|
let inviteCode = "your invite code"
|
||||||
|
let config = breez_sdk.defaultConfig(envType: EnvironmentType.production, apiKey: "",
|
||||||
|
nodeConfig: NodeConfig.greenlight(
|
||||||
|
config: GreenlightNodeConfig(partnerCredentials: nil,inviteCode: inviteCode)));
|
||||||
|
|
||||||
// Customize the config object according to your needs
|
// Customize the config object according to your needs
|
||||||
config.apiKey = "your API key"
|
|
||||||
config.workingDir = "path to an existing directory"
|
config.workingDir = "path to an existing directory"
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let sdk = try initServices(config: config, seed: seed, creds: credentials, listener: SDKListener());
|
// Connect to the Breez SDK make it ready for use
|
||||||
try sdk.start();
|
let sdk = try connect(config: config, seed: seed, listener: SDKListener());
|
||||||
} catch{
|
} catch{
|
||||||
// handle error
|
// handle error
|
||||||
}
|
}
|
||||||
@@ -140,30 +101,6 @@ do {
|
|||||||
<div slot="title">React Native</div>
|
<div slot="title">React Native</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
The first step is to register a new node. In order to do that a seed is needed.
|
|
||||||
## Registering a new node
|
|
||||||
```typescript
|
|
||||||
try {
|
|
||||||
const seed = await mnemonicToSeed("<mnemonics words>");
|
|
||||||
const inviteCode = "<your greenlight invite code>";
|
|
||||||
|
|
||||||
// register_node takes either greenlight credentials (certifate & key) or invite code.
|
|
||||||
// At this example we are using the invite code option.
|
|
||||||
const credentials = await registerNode(Network.BITCOIN, seed, null, inviteCode);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recovering an existing node
|
|
||||||
```typescript
|
|
||||||
const seed = await mnemonicToSeed("<mnemonics words>");
|
|
||||||
const credentials = await recoverNode(Network.BITCOIN, seed);
|
|
||||||
```
|
|
||||||
|
|
||||||
Once the credentials are retrieved they should be saved in a secured storage.
|
|
||||||
The next step is to initialize the SDK and start the node:
|
|
||||||
|
|
||||||
## Initializing the SDK
|
## Initializing the SDK
|
||||||
```typescript
|
```typescript
|
||||||
|
|
||||||
@@ -173,15 +110,25 @@ addEventListener((type, data) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Create the default config
|
// Create the default config
|
||||||
let config = defaultConfig(EnvironmentType.PRODUCTION)
|
const seed = await mnemonicToSeed("<mnemonics words>");
|
||||||
|
const inviteCode = "<your greenlight invite code>";
|
||||||
|
const nodeConfig : NodeConfig = {
|
||||||
|
type: "greenlight",
|
||||||
|
config: {
|
||||||
|
partnerCredentials: {
|
||||||
|
deviceKey: null,
|
||||||
|
deviceCert: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let config = defaultConfig(EnvironmentType.PRODUCTION, "api key", nodeConfig);
|
||||||
|
|
||||||
// Customize the config object according to your needs
|
// Customize the config object according to your needs
|
||||||
config.apiKey = "your API key";
|
|
||||||
config.workingDir = "path to an existing directory";
|
config.workingDir = "path to an existing directory";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const sdkServices = await initServices(config, credentials.deviceKey, credentials.deviceCert, seed);
|
// Connect to the Breez SDK make it ready for use
|
||||||
await start();
|
const sdkServices = await connect(config seed);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
@@ -202,31 +149,7 @@ try {
|
|||||||
<div slot="title">Dart</div>
|
<div slot="title">Dart</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
The first step is to register a new node. In order to do that a seed is needed.
|
## Connecting
|
||||||
## Registering a new node
|
|
||||||
```dart
|
|
||||||
try {
|
|
||||||
Config config = await defaultConfig(configType: EnvironmentType.Production);
|
|
||||||
Uint8List seed = await mnemonicToSeed(phrase: "<mnemonic words>");
|
|
||||||
String inviteCode = "<your greenlight invite code>";
|
|
||||||
|
|
||||||
// registerNode takes either greenlight credentials (certifate & key) or invite code.
|
|
||||||
// At this example we are using the invite code option.
|
|
||||||
GreenlightCredentials credentials = await registerNode(network: Network.Bitcoin, seed: seed, config: config, inviteCode: inviteCode);
|
|
||||||
} catch (error) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recovering an existing node
|
|
||||||
```dart
|
|
||||||
Config config = await defaultConfig(configType: EnvironmentType.Production);
|
|
||||||
Uint8List seed = await mnemonicToSeed("<mnemonics words>");
|
|
||||||
GreenlightCredentials credentials = await recoverNode(network: Network.Bitcoin, seed: seed, config: config);
|
|
||||||
```
|
|
||||||
Once the credentials are retrieved they should be saved in a secured storage.
|
|
||||||
The next step is to initialize the SDK and start the node:
|
|
||||||
## Initializing the SDK
|
|
||||||
```dart
|
```dart
|
||||||
// SDK events listener
|
// SDK events listener
|
||||||
breezEventsStream().listen((event) {
|
breezEventsStream().listen((event) {
|
||||||
@@ -239,15 +162,17 @@ breezLogStream().listen((log) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the default config
|
// Create the default config
|
||||||
Config config = await defaultConfig(configType: EnvironmentType.Production);
|
Uint8List seed = await mnemonicToSeed(phrase: "<mnemonic words>");
|
||||||
|
String inviteCode = "<your greenlight invite code>";
|
||||||
|
NodeConfg nodeConfig = NodeConfig.Greenlight(config: GreenlightNodeConfig(partnerCredentials: null, inviteCode: inviteCode));
|
||||||
|
Config config = await defaultConfig(configType: EnvironmentType.Production, apiKey: "", nodeConfig: nodeConfig);
|
||||||
|
|
||||||
// Customize the config object according to your needs
|
// Customize the config object according to your needs
|
||||||
config.apiKey = "your API key";
|
|
||||||
config.workingDir = "path to an existing directory";
|
config.workingDir = "path to an existing directory";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await initServices(config: config, seed: seed, creds: creds);
|
// Connect to the Breez SDK make it ready for use
|
||||||
await startNode();
|
await connect(config: config, seed: seed);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// handle error
|
// handle error
|
||||||
}
|
}
|
||||||
@@ -267,31 +192,7 @@ try {
|
|||||||
<div slot="title">Python</div>
|
<div slot="title">Python</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
The first step is to register a new node. In order to do that a seed is needed.
|
## Connecting
|
||||||
|
|
||||||
## Registering a new node
|
|
||||||
```python
|
|
||||||
try :
|
|
||||||
seed = mnemonic_to_seed("<mnemonics words>")
|
|
||||||
invite_code = "<your greenlight invite code>"
|
|
||||||
|
|
||||||
# register_node takes either greenlight credentials (certifate & key) or invite code.
|
|
||||||
# At this example we are using the invite code option.
|
|
||||||
credentials = register_node(Network.BITCOIN, seed, inviteCode)
|
|
||||||
except Exception as error:
|
|
||||||
# Handle error
|
|
||||||
```
|
|
||||||
|
|
||||||
## Recovering an existing node
|
|
||||||
```python
|
|
||||||
seed = mnemonic_to_seed("<mnemonics words>")
|
|
||||||
credentials = recover_node(Network.BITCOIN, seed)
|
|
||||||
```
|
|
||||||
|
|
||||||
Once the credentials are retrieved they should be saved in a secured storage.
|
|
||||||
The next step is to initialize the SDK and start the node:
|
|
||||||
|
|
||||||
## Initializing the SDK
|
|
||||||
```python
|
```python
|
||||||
# SDK events listener
|
# SDK events listener
|
||||||
class SDKListener(breez_sdk.EventListener):
|
class SDKListener(breez_sdk.EventListener):
|
||||||
@@ -299,15 +200,17 @@ class SDKListener(breez_sdk.EventListener):
|
|||||||
print(event)
|
print(event)
|
||||||
|
|
||||||
# Create the default config
|
# Create the default config
|
||||||
config = default_config(EnvironmentType.PRODUCTION)
|
seed = mnemonic_to_seed("<mnemonics words>")
|
||||||
|
invite_code = "<your greenlight invite code>"
|
||||||
|
config = breez_sdk.default_config(breez_sdk.EnvironmentType.PRODUCTION, "code",
|
||||||
|
breez_sdk.NodeConfig.GREENLIGHT(breez_sdk.GreenlightNodeConfig(None, invite_code)))
|
||||||
|
|
||||||
# Customize the config object according to your needs
|
# Customize the config object according to your needs
|
||||||
config.api_key = "your API key"
|
|
||||||
config.working_dir = "path to an existing directory"
|
config.working_dir = "path to an existing directory"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sdk_services = init_services(config,seed,creds,SDKListener())
|
# Connect to the Breez SDK make it ready for use
|
||||||
sdk_services.start()
|
sdk_services = breez_sdk.connect(config, seed, SDKListener())
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
# Handle error
|
# Handle error
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user