mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 06:14:21 +01:00
Merge branch 'connect-api' into go-examples
# Conflicts: # src/guide/getting_started.md # src/guide/lnurl_auth.md # src/guide/lnurl_pay.md # src/guide/lnurl_withdraw.md # src/guide/payments.md # src/guide/receive_onchain.md # src/guide/send_onchain.md
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.)
|
||||
* 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
|
||||
|
||||
@@ -19,44 +19,30 @@ Breez SDK is available in several platforms. Follow the [Installing](install.md)
|
||||
<div slot="title">Rust</div>
|
||||
<section>
|
||||
|
||||
The first step is to register a new node. In order to do that a seed is needed.
|
||||
## 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
|
||||
## Connecting
|
||||
```rust,no_run
|
||||
// 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
|
||||
config.api_key = Some("your API key".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,
|
||||
seed.to_vec(),
|
||||
credentials.clone(),
|
||||
seed.to_vec(),
|
||||
Box::new(AppEventListener {}),
|
||||
)
|
||||
.await?;
|
||||
|
||||
BreezServices::start(rt(), &sdk).await?;
|
||||
```
|
||||
|
||||
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>
|
||||
<section>
|
||||
|
||||
The first step is to register a new node
|
||||
## 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
|
||||
## Connecting
|
||||
```swift
|
||||
|
||||
// SDK events listener
|
||||
@@ -110,15 +68,18 @@ class SDKListener: EventListener {
|
||||
}
|
||||
|
||||
// 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
|
||||
config.apiKey = "your API key";
|
||||
config.workingDir = "path to an existing directory";
|
||||
config.workingDir = "path to an existing directory"
|
||||
|
||||
do {
|
||||
let sdk = try initServices(config: config, seed: seed, creds: credentials, listener: SDKListener());
|
||||
try sdk.start();
|
||||
do {
|
||||
// Connect to the Breez SDK make it ready for use
|
||||
let sdk = try connect(config: config, seed: seed, listener: SDKListener());
|
||||
} catch{
|
||||
// handle error
|
||||
}
|
||||
@@ -140,31 +101,7 @@ do {
|
||||
<div slot="title">React Native</div>
|
||||
<section>
|
||||
|
||||
The first step is to register a new node
|
||||
## 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
|
||||
## Connecting
|
||||
```typescript
|
||||
|
||||
// SDK events listener
|
||||
@@ -173,15 +110,22 @@ addEventListener((type, data) => {
|
||||
})
|
||||
|
||||
// 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: NodeConfigType.GREENLIGHT,
|
||||
config: {
|
||||
inviteCode: "your invite code"
|
||||
}
|
||||
}
|
||||
let config = defaultConfig(EnvironmentType.PRODUCTION, "api key", nodeConfig);
|
||||
|
||||
// Customize the config object according to your needs
|
||||
config.apiKey = "your API key";
|
||||
config.workingDir = "path to an existing directory";
|
||||
|
||||
try {
|
||||
const sdkServices = await initServices(config, credentials.deviceKey, credentials.deviceCert, seed);
|
||||
await start();
|
||||
// Connect to the Breez SDK make it ready for use
|
||||
const sdkServices = await connect(config, seed);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
@@ -199,32 +143,90 @@ try {
|
||||
}
|
||||
```
|
||||
</section>
|
||||
<div slot="title">Dart</div>
|
||||
<section>
|
||||
|
||||
## Connecting
|
||||
```dart
|
||||
// SDK events listener
|
||||
breezEventsStream().listen((event) {
|
||||
print("Received Breez event: $event");
|
||||
}
|
||||
|
||||
// SDK logs listener
|
||||
breezLogStream().listen((log) {
|
||||
print("Received Breez log entry: $log");
|
||||
}
|
||||
|
||||
// Create the default config
|
||||
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
|
||||
config.workingDir = "path to an existing directory";
|
||||
|
||||
try {
|
||||
// Connect to the Breez SDK make it ready for use
|
||||
await connect(config: config, seed: seed);
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
```
|
||||
At any point we can fetch our balance from the Greenlight node:
|
||||
|
||||
```dart
|
||||
try {
|
||||
NodeState? nodeInfo = await nodeInfo();
|
||||
int lnBalance = nodeInfo?.channelsBalanceMsat;
|
||||
int onchainBalance = nodeInfo?.onchainBalanceMsat;
|
||||
} catch (error) {
|
||||
// handle error
|
||||
}
|
||||
```
|
||||
</section>
|
||||
<div slot="title">Python</div>
|
||||
<section>
|
||||
|
||||
## Connecting
|
||||
```python
|
||||
# SDK events listener
|
||||
class SDKListener(breez_sdk.EventListener):
|
||||
def on_event(self, event):
|
||||
print(event)
|
||||
|
||||
# Create the default config
|
||||
seed = mnemonic_to_seed("<mnemonics words>")
|
||||
invite_code = "<your greenlight invite code>"
|
||||
config = breez_sdk.default_config(breez_sdk.EnvironmentType.PRODUCTION, "api key",
|
||||
breez_sdk.NodeConfig.GREENLIGHT(breez_sdk.GreenlightNodeConfig(None, invite_code)))
|
||||
|
||||
# Customize the config object according to your needs
|
||||
config.working_dir = "path to an existing directory"
|
||||
|
||||
try:
|
||||
# Connect to the Breez SDK make it ready for use
|
||||
sdk_services = breez_sdk.connect(config, seed, SDKListener())
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```
|
||||
|
||||
At any point we can fetch our balance from the Greenlight node:
|
||||
|
||||
```python
|
||||
try:
|
||||
node_info = node_info()
|
||||
ln_balance = node_info.channels_balance_msat
|
||||
onchain_balance = node_info.onchain_balance_msat
|
||||
except Exception as error:
|
||||
# Handle error
|
||||
```
|
||||
</section>
|
||||
<div slot="title">Go</div>
|
||||
<section>
|
||||
|
||||
The first step is to register a new node
|
||||
## Registering a new node
|
||||
```go
|
||||
if seed, err := breez_sdk.MnemonicToSeed("<mnemonics words>"); err != nil {
|
||||
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.
|
||||
credentials, err := breez_sdk.RegisterNode(breez_sdk.NetworkBitcoin, seed, nil, &inviteCode)
|
||||
}
|
||||
```
|
||||
|
||||
## Recovering an existing node
|
||||
```go
|
||||
if seed, err := breez_sdk.MnemonicToSeed("<mnemonics words>"); err != nil {
|
||||
credentials := breez_sdk.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
|
||||
## Connecting
|
||||
```go
|
||||
// SDK events listener
|
||||
type BreezListener struct{}
|
||||
@@ -234,17 +236,24 @@ func (BreezListener) OnEvent(e breez_sdk.BreezEvent) {
|
||||
}
|
||||
|
||||
// Create the default config
|
||||
config := breez_sdk.DefaultConfig(breez_sdk.EnvironmentTypeProduction)
|
||||
apiKey := "<your breez api key>"
|
||||
inviteCode := "<your greenlight invite code>"
|
||||
nodeConfig := breez_sdk.NodeConfigGreenlight{
|
||||
Config: breez_sdk.GreenlightNodeConfig{
|
||||
PartnerCredentials: nil,
|
||||
InviteCode: &inviteCode,
|
||||
},
|
||||
}
|
||||
|
||||
config := breez_sdk.DefaultConfig(breez_sdk.EnvironmentTypeProduction, apiKey, nodeConfig)
|
||||
|
||||
// Customize the config object according to your needs
|
||||
config.apiKey = "your API key"
|
||||
config.workingDir = "path to an existing directory"
|
||||
|
||||
if sdkServices, err := breez_sdk.InitServices(config, seed, credentials, BreezListener{}); err != nil {
|
||||
if sdkServices, err := breez_sdk.Connect(config, seed, BreezListener{}); err != nil {
|
||||
sdkServices.Start()
|
||||
}
|
||||
```
|
||||
|
||||
At any point we can fetch our balance from the Greenlight node:
|
||||
|
||||
```go
|
||||
|
||||
Reference in New Issue
Block a user