mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 14:24:19 +01:00
Merge pull request #52 from breez/savage-rn-connect
Update RN connect interface
This commit is contained in:
@@ -132,27 +132,27 @@ try {
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// SDK events listener
|
// SDK events listener
|
||||||
addEventListener((type, data) => {
|
const onBreezEvent = (event: BreezEvent) => {
|
||||||
console.log(`received event ${type}`);
|
console.log(`received event ${event.type}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create the default config
|
// Create the default config
|
||||||
const seed = await mnemonicToSeed("<mnemonics words>");
|
const seed = await mnemonicToSeed("<mnemonics words>")
|
||||||
const inviteCode = "<your greenlight invite code>";
|
const inviteCode = "<your greenlight invite code>"
|
||||||
const nodeConfig : NodeConfig = {
|
const nodeConfig : NodeConfig = {
|
||||||
type: NodeConfigType.GREENLIGHT,
|
type: NodeConfigType.GREENLIGHT,
|
||||||
config: {
|
config: {
|
||||||
inviteCode: "your invite code"
|
inviteCode: "your invite code"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let config = await defaultConfig(EnvironmentType.PRODUCTION, "api key", nodeConfig);
|
let config = await defaultConfig(EnvironmentType.PRODUCTION, "api key", nodeConfig)
|
||||||
|
|
||||||
// Customize the config object according to your needs
|
// Customize the config object according to your needs
|
||||||
config.workingDir = "path to an existing directory";
|
config.workingDir = "path to an existing directory"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Connect to the Breez SDK make it ready for use
|
// Connect to the Breez SDK make it ready for use
|
||||||
const sdkServices = await connect(config, seed);
|
const sdkServices = await connect(config, seed, onBreezEvent)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,16 +79,16 @@ try {
|
|||||||
```typescript
|
```typescript
|
||||||
// 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"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const input = await parseInput(lnurlAuthUrl)
|
const input = await parseInput(lnurlAuthUrl)
|
||||||
if (input.type === InputType.LNURL_AUTH) {
|
if (input.type === InputTypeVariant.LN_URL_AUTH) {
|
||||||
const result = await lnurlAuth(input.data)
|
const result = await lnurlAuth(input.data)
|
||||||
if (result.status === "ok") {
|
if (result.type === LnUrlCallbackStatusVariant.OK) {
|
||||||
print("Successfully authenticated")
|
console.log("Successfully authanticated")
|
||||||
} else {
|
} else {
|
||||||
print("Failed to authenticate")
|
console.log("Failed to authenticate")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ try {
|
|||||||
// Endpoint can also be of the form:
|
// Endpoint can also be of the form:
|
||||||
// lnurlp://domain.com/lnurl-pay?key=val
|
// lnurlp://domain.com/lnurl-pay?key=val
|
||||||
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
||||||
let lnurlPayUrl = "lightning@address.com";
|
let lnurlPayUrl = "lightning@address.com"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const input = await parseInput(lnurlPayUrl)
|
const input = await parseInput(lnurlPayUrl)
|
||||||
if (input.type === InputType.LNURL_PAY) {
|
if (input.type === InputTypeVariant.LN_URL_PAY) {
|
||||||
const amountSats = input.data.minSendable;
|
const amountSats = input.data.minSendable
|
||||||
const result = await payLnurl(input.data, amountSats, "comment")
|
const result = await payLnurl(input.data, amountSats, "comment")
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -70,12 +70,12 @@ try {
|
|||||||
```typescript
|
```typescript
|
||||||
// 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"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const input = await parseInput(lnurlWithdrawUrl)
|
const input = await parseInput(lnurlWithdrawUrl)
|
||||||
if (input.type === InputType.LNURL_WITHDRAW) {
|
if (input.type === InputTypeVariant.LN_URL_WITHDRAW) {
|
||||||
const amountSats = input.data.minWithdrawable;
|
const amountSats = input.data.minWithdrawable
|
||||||
const result = await withdrawLnurl(input.data, amountSats, "comment")
|
const result = await withdrawLnurl(input.data, amountSats, "comment")
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ try {
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const bolt11 = "...";
|
const bolt11 = "..."
|
||||||
try {
|
try {
|
||||||
const payment = await sendPayment(bolt11, 3000)
|
const payment = await sendPayment(bolt11, 3000)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -285,7 +285,7 @@ try {
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const nodeId = "...";
|
const nodeId = "..."
|
||||||
try {
|
try {
|
||||||
const payment = await sendSpontaneousPayment(nodeId, 3000)
|
const payment = await sendSpontaneousPayment(nodeId, 3000)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ try {
|
|||||||
const swapInfo = await receiveOnchain({})
|
const swapInfo = await receiveOnchain({})
|
||||||
|
|
||||||
// Send your funds to the below bitcoin address
|
// Send your funds to the below bitcoin address
|
||||||
const address = swapInfo.bitcoinAddress;
|
const address = swapInfo.bitcoinAddress
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ try {
|
|||||||
try {
|
try {
|
||||||
const currentFees = await fetchReverseSwapFees({sendAmountSat: 50000})
|
const currentFees = await fetchReverseSwapFees({sendAmountSat: 50000})
|
||||||
|
|
||||||
console.log(`Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}`);
|
console.log(`Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
@@ -162,8 +162,8 @@ Log.v("Breez", "Maximum amount, in sats: ${fees.max}")
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
console.log(`Minimum amount, in sats: ${currentFees.min}`);
|
console.log(`Minimum amount, in sats: ${currentFees.min}`)
|
||||||
console.log(`Maximum amount, in sats: ${currentFees.max}`);
|
console.log(`Maximum amount, in sats: ${currentFees.max}`)
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -257,8 +257,8 @@ try {
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const destinationAddress = "bc1..";
|
const destinationAddress = "bc1.."
|
||||||
const amountSat = currentFees.min;
|
const amountSat = currentFees.min
|
||||||
const satPerVbyte = <fee rate>
|
const satPerVbyte = <fee rate>
|
||||||
try {
|
try {
|
||||||
const reverseSwapInfo = await sendOnchain(amountSat, destinationAddress, currentFees.feesHash, satPerVbyte)
|
const reverseSwapInfo = await sendOnchain(amountSat, destinationAddress, currentFees.feesHash, satPerVbyte)
|
||||||
@@ -387,8 +387,8 @@ for (rs in sdk.inProgressReverseSwaps()) {
|
|||||||
```typescript
|
```typescript
|
||||||
try {
|
try {
|
||||||
const swaps = await inProgressReverseSwaps()
|
const swaps = await inProgressReverseSwaps()
|
||||||
for (const swap in swaps) {
|
for (const swap of swaps) {
|
||||||
println(`Reverse swap ${swap.id} in progress, status is ${swap.status}`);
|
console.log(`Reverse swap ${swap.id} in progress, status is ${swap.status}`)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
|||||||
Reference in New Issue
Block a user