mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-19 06:44:19 +01:00
Merge branch 'main' into typo-fixes
# Conflicts: # src/guide/send_onchain.md
This commit is contained in:
@@ -75,21 +75,25 @@ The first step is to register a new node
|
|||||||
## Registering a new node
|
## Registering a new node
|
||||||
```swift
|
```swift
|
||||||
do {
|
do {
|
||||||
let seed = try mnemonicToSeed(phrase: "<mnemonics words>");
|
let seed = try mnemonicToSeed(phrase: "<mnemonics words>")
|
||||||
let invite_code = <your greenlight invite code>;
|
let inviteCode = ""
|
||||||
|
|
||||||
// register_node takes either greenlight credentials (certifate & key) or invite code.
|
// register_node takes either greenlight credentials (certifate & key) or invite code.
|
||||||
// At this example we are using the invite code option.
|
// At this example we are using the invite code option.
|
||||||
let credentials = try registerNode(network: Network.bitcoin, seed: seed, inviteCode: inviteCode);
|
let credentials = try registerNode(network: Network.bitcoin, seed: seed, registerCredentials: nil, inviteCode: inviteCode)
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Recovering an existing node
|
## Recovering an existing node
|
||||||
```swift
|
```swift
|
||||||
let seed = try mnemonicToSeed(phrase: "<mnemonics words>");
|
do {
|
||||||
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
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Once the credentials are retrieved they should be saved in a secured storage.
|
Once the credentials are retrieved they should be saved in a secured storage.
|
||||||
@@ -101,22 +105,22 @@ The next step is to initialize the SDK and start the node:
|
|||||||
// SDK events listener
|
// SDK events listener
|
||||||
class SDKListener: EventListener {
|
class SDKListener: EventListener {
|
||||||
func onEvent(e: BreezEvent) {
|
func onEvent(e: BreezEvent) {
|
||||||
print("received event ", e);
|
print("received event ", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the default config
|
// Create the default config
|
||||||
let config = breez_sdk.defaultConfig(envType: EnvironmentType.production)
|
var config = defaultConfig(envType: EnvironmentType.production)
|
||||||
|
|
||||||
// Customize the config object according to your needs
|
// Customize the config object according to your needs
|
||||||
config.apiKey = "your API key";
|
config.apiKey = "your API key";
|
||||||
config.workingDir = "path to an existing directory";
|
config.workingDir = "path to an existing directory";
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let sdkServices = try initServices(config: config, seed: seed, creds: credentials, listener: SDKListener());
|
let sdk = try initServices(config: config, seed: seed, creds: credentials, listener: SDKListener());
|
||||||
try sdkServices.start();
|
try sdk.start();
|
||||||
} catch SdkError.Error(let message) {
|
} catch{
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -124,11 +128,11 @@ At any point we can fetch our balance from the Greenlight node:
|
|||||||
|
|
||||||
```swift
|
```swift
|
||||||
do {
|
do {
|
||||||
let nodeInfo = try sdkServices.nodeInfo();
|
let nodeInfo = try sdk.nodeInfo()
|
||||||
let lnBalance = nodeInfo.channelsBalanceMsat;
|
let lnBalance = nodeInfo?.channelsBalanceMsat
|
||||||
let onchainBalance = nodeInfo.onchainBalanceMsat;
|
let onchainBalance = nodeInfo?.onchainBalanceMsat
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -31,21 +31,21 @@ if let Ok(LnUrlAuth{data: ad}) = parse(lnurl_auth_url).await {
|
|||||||
```swift
|
```swift
|
||||||
// Endpoint can also be of the form:
|
// Endpoint can also be of the form:
|
||||||
// keyauth://domain.com/auth?key=val
|
// keyauth://domain.com/auth?key=val
|
||||||
let lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
|
let lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let inputType = try parseInput(s: lnurlAuthUrl)
|
let inputType = try parseInput(s: lnurlAuthUrl)
|
||||||
if case .lnUrlAuth(data) = inputType {
|
if case .lnUrlAuth(let data) = inputType {
|
||||||
let result = try sdk.lnurlAuth(data)
|
let result = try sdk.lnurlAuth(reqData: data)
|
||||||
switch result {
|
switch result {
|
||||||
case .ok:
|
case .ok:
|
||||||
print("Successfully authenticated")
|
print("Successfully authenticated")
|
||||||
case .errorStatus(data):
|
case .errorStatus(let data):
|
||||||
print("Failed to authenticate")
|
print("Failed to authenticate")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ if let Ok(LnUrlPay{data: pd}) = parse(lnurl_pay_url).await {
|
|||||||
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
||||||
let lnurlPayUrl = "lightning@address.com";
|
let lnurlPayUrl = "lightning@address.com";
|
||||||
do {
|
do {
|
||||||
let inputType = try parseInput(s: input)
|
let inputType = try parseInput(s: lnurlPayUrl)
|
||||||
if case .lnUrlPay(data) = inputType {
|
if case .lnUrlPay(let data) = inputType {
|
||||||
let amountSats = inputType.minSendable;
|
let amountSats = data.minSendable;
|
||||||
try sdk.payLnurl(amountSats: amountSats, "comment", reqData: data)
|
try sdk.payLnurl(reqData: data, amountSats: amountSats, comment: "comment")
|
||||||
}
|
}
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -27,17 +27,17 @@ if let Ok(LnUrlWithdraw{data: wd}) = parse(lnurl_withdraw_url).await {
|
|||||||
```swift
|
```swift
|
||||||
// Endpoint can also be of the form:
|
// Endpoint can also be of the form:
|
||||||
// lnurlw://domain.com/lnurl-withdraw?key=val
|
// lnurlw://domain.com/lnurl-withdraw?key=val
|
||||||
let lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
|
let lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let inputType = try parseInput(s: input)
|
let inputType = try parseInput(s: lnurlWithdrawUrl)
|
||||||
if case .lnUrlWithdraw(data) = inputType {
|
if case .lnUrlWithdraw(let data) = inputType {
|
||||||
let amountSat = data.minWithdrawable;
|
let amountSat = data.minWithdrawable
|
||||||
let description = "Test withdraw"
|
let description = "Test withdraw"
|
||||||
try sdk.withdrawLnurl(amountSats: amountSat, description: "comment", reqData: data)
|
try sdk.withdrawLnurl(reqData: data, amountSats: amountSat, description: "comment")
|
||||||
}
|
}
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ Breez SDK automatically connects your node to the LSP peer and you can now recei
|
|||||||
```swift
|
```swift
|
||||||
do {
|
do {
|
||||||
let invoice = try sdk.receivePayment(amountSats: 3000, description: "Invoice for 3000 sats")
|
let invoice = try sdk.receivePayment(amountSats: 3000, description: "Invoice for 3000 sats")
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -45,8 +45,8 @@ do {
|
|||||||
let bolt11 = "...";
|
let bolt11 = "...";
|
||||||
do {
|
do {
|
||||||
let payment = try sdk.sendPayment(bolt11: bolt11, amountSats: 3000)
|
let payment = try sdk.sendPayment(bolt11: bolt11, amountSats: 3000)
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -55,8 +55,8 @@ do {
|
|||||||
let nodeId = "...";
|
let nodeId = "...";
|
||||||
do {
|
do {
|
||||||
let payment = try sdk.sendSpontaneousPayment(nodeId: nodeId, amountSats: 3000)
|
let payment = try sdk.sendSpontaneousPayment(nodeId: nodeId, amountSats: 3000)
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ sdk.refund(refundable.bitcoin_address, destination_address, sat_per_vbyte).await
|
|||||||
|
|
||||||
```swift
|
```swift
|
||||||
do {
|
do {
|
||||||
let swapInfo = try sdk.receiveOnchain();
|
let swapInfo = try sdk.receiveOnchain()
|
||||||
|
|
||||||
// Send your funds to the below bitcoin address
|
// Send your funds to the bellow bitcoin address
|
||||||
let address = swapInfo.bitcoinAddress;
|
let address = swapInfo.bitcoinAddress;
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -56,8 +56,8 @@ Once you've sent the funds to the above address, the SDK will monitor this addre
|
|||||||
```swift
|
```swift
|
||||||
do {
|
do {
|
||||||
let swapInfo = try sdk.inProgressSwap()
|
let swapInfo = try sdk.inProgressSwap()
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -71,8 +71,8 @@ In order to execute a refund, you need to supply an on-chain address to where th
|
|||||||
```swift
|
```swift
|
||||||
do {
|
do {
|
||||||
let refundables = try sdk.listRefundables()
|
let refundables = try sdk.listRefundables()
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -81,12 +81,14 @@ Once you have a refundable swap in hand, use the follwing code to execute a refu
|
|||||||
```swift
|
```swift
|
||||||
let destinationAddress = "..."
|
let destinationAddress = "..."
|
||||||
let satPerVbyte = <refund tx fee rate>
|
let satPerVbyte = <refund tx fee rate>
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try sdk.refund(swapAddress: refundable.bitcoinAddress,
|
try sdk.refund(
|
||||||
toAddress: destinationAddress,
|
swapAddress: "",
|
||||||
satPerVbyte: satPerVbyte)
|
toAddress: destinationAddress,
|
||||||
} catch SdkError.Error(let message) {
|
satPerVbyte: satPerVbyte)
|
||||||
print(message)
|
} catch {
|
||||||
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -55,11 +55,11 @@ for rs in sdk.in_progress_reverse_swaps().await? {
|
|||||||
try {
|
try {
|
||||||
let currentFees = try sdk.fetchReverseSwapFees()
|
let currentFees = try sdk.fetchReverseSwapFees()
|
||||||
|
|
||||||
println("Percentage fee for the reverse swap service: \(currentFees.feesPercentage)");
|
println("Percentage fee for the reverse swap service: \(currentFees.feesPercentage)")
|
||||||
println("Estimated miner fees in sats for locking up funds: \(currentFees.feesLockup)");
|
println("Estimated miner fees in sats for locking up funds: \(currentFees.feesLockup)")
|
||||||
println("Estimated miner fees in sats for claiming funds: \(currentFees.feesClaim)");
|
println("Estimated miner fees in sats for claiming funds: \(currentFees.feesClaim)")
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -70,20 +70,20 @@ of the total costs.
|
|||||||
Fetching the fees also tells you what is the range of amounts you can send:
|
Fetching the fees also tells you what is the range of amounts you can send:
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
println("Minimum amount, in sats: \(currentFees.min)");
|
println("Minimum amount, in sats: \(current_fees.min)")
|
||||||
println("Maximum amount, in sats: \(currentFees.max)");
|
println("Maximum amount, in sats: \(current_fees.max)")
|
||||||
```
|
```
|
||||||
|
|
||||||
Once you checked the fees are acceptable, you can start the reverse swap:
|
Once you checked the fees are acceptable, you can start the reverse swap:
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
let destinationAddress = "bc1..";
|
let destinationAddress = "bc1.."
|
||||||
let amountSat = currentFees.min;
|
let amountSat = currentFees.min
|
||||||
let satPerVbyte = <fee rate>
|
let satPerVbyte = <fee rate>
|
||||||
try {
|
try {
|
||||||
try sdk.sendOnchain(amountSat: amountSat, onchainRecipientAddress: destinationAddress, pairHash: currentFees.feesHash, satPerVbyte: satPerVbyte)
|
try sdk.sendOnchain(amountSat: amountSat, onchainRecipientAddress: destinationAddress, pairHash: currentFees.feesHash, satPerVbyte: satPerVbyte)
|
||||||
} catch SdkError.Error(let message) {
|
} catch {
|
||||||
print(message)
|
// handle error
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ You can check its status with:
|
|||||||
|
|
||||||
```swift
|
```swift
|
||||||
for rs in sdk.inProgressReverseSwaps() {
|
for rs in sdk.inProgressReverseSwaps() {
|
||||||
println("Reverse swap \(rs.id) in progress, status is \(rs.breezStatus)");
|
println("Reverse swap \(rs.id) in progress, status is \(rs.breezStatus)")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
@@ -121,8 +121,8 @@ of the total costs.
|
|||||||
Fetching the fees also tells you what is the range of amounts you can send:
|
Fetching the fees also tells you what is the range of amounts you can send:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
console.log(`Minimum amount, in sats: ${currentFees.min}`);
|
console.log(`Minimum amount, in sats: ${current_fees.min}`);
|
||||||
console.log(`Maximum amount, in sats: ${currentFees.max}`);
|
console.log(`Maximum amount, in sats: ${current_fees.max}`);
|
||||||
```
|
```
|
||||||
|
|
||||||
Once you checked the fees are acceptable, you can start the reverse swap:
|
Once you checked the fees are acceptable, you can start the reverse swap:
|
||||||
|
|||||||
Reference in New Issue
Block a user