Merge branch 'multi-lang-tabs' of github.com:breez/breez-sdk-docs into multi-lang-tabs

* 'multi-lang-tabs' of github.com:breez/breez-sdk-docs:
  Remove sdkServices as its managed by the native module
  Add React Native examples
  Indentation fixes
This commit is contained in:
Roei Erez
2023-07-03 19:38:37 +03:00
7 changed files with 312 additions and 49 deletions

View File

@@ -80,7 +80,7 @@ do {
// 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);
let credentials = try registerNode(network: Network.bitcoin, seed: seed, registerCredentials: nil, inviteCode: inviteCode);
} catch {
// handle error
}
@@ -89,8 +89,8 @@ do {
## Recovering an existing node
```swift
do {
let seed = try mnemonicToSeed(phrase: "<mnemonics words>");
let credentials = try recoverNode(network: Network.bitcoin, seed: seed);
let seed = try mnemonicToSeed(phrase: "<mnemonics words>");
let credentials = try recoverNode(network: Network.bitcoin, seed: seed);
} catch {
// handle error
}
@@ -104,9 +104,9 @@ The next step is to initialize the SDK and start the node:
// SDK events listener
class SDKListener: EventListener {
func onEvent(e: BreezEvent) {
print("received event ", e);
}
func onEvent(e: BreezEvent) {
print("received event ", e);
}
}
// Create the default config
@@ -117,8 +117,8 @@ config.apiKey = "your API key";
config.workingDir = "path to an existing directory";
do {
let sdk = try initServices(config: config, seed: seed, creds: credentials, listener: SDKListener());
try sdk.start();
let sdk = try initServices(config: config, seed: seed, creds: credentials, listener: SDKListener());
try sdk.start();
} catch{
// handle error
}
@@ -127,15 +127,77 @@ do {
At any point we can fetch our balance from the Greenlight node:
```swift
do {
let nodeInfo = try sdk.nodeInfo();
let lnBalance = nodeInfo?.channelsBalanceMsat;
let onchainBalance = nodeInfo?.onchainBalanceMsat;
do {
let nodeInfo = try sdk.nodeInfo();
let lnBalance = nodeInfo?.channelsBalanceMsat;
let onchainBalance = nodeInfo?.onchainBalanceMsat;
} catch {
// handle error
}
```
</section>
<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 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.
const credentials = await registerNode(Network.BITCOIN, seed, 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
```typescript
// SDK events listener
addEventListener((type, data) => {
console.log(`received event ${type}`);
})
// Create the default config
let config = defaultConfig(EnvironmentType.PRODUCTION)
// 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();
} catch (error) {
console.log(error);
}
```
At any point we can fetch our balance from the Greenlight node:
```typescript
try {
const nodeInfo = await nodeInfo();
const lnBalance = nodeInfo.channelsBalanceMsat;
const onchainBalance = nodeInfo.onchainBalanceMsat;
} catch (error) {
console.log(error);
}
```
</section>
</custom-tabs>