A Swift Package for interacting with LNBits.
- Add it using XCode menu File > Swift Package > Add Package Dependency
- Add https://github.com/FlorianHubl/LNBitsKit as Swift Package URL
- Click on the package
- Click Add Package and you are done
- iOS 13 or higher
- macOS 12 or higher
let lnbits = LNBits(server: "https://legend.lnbits.com", adminKey: "145a510c4ce1496e827e1fc34934b980", invoiceKey: "a04c53fec8524ba3aa63d8385e41c288")
These keys are in the Api docs in your LNBits Wallet.
if await lnbits.testConnection() {
// connected
}else {
// not connected
}
let invoice = try! await lnbits.createInvoice(sats: 21, memo: "Hello :)")
let paymentRequest = invoice.paymentRequest
let decodeInvoice = try! await lnbits.decodeInvoice(invoice: "lnbc210n1pjd62g3sp5pwlfye29mk6mmsxzhj8w3cvq4va3tu2uwj2klwjqpguzhw67x38qpp5upej4ls9ytz7ard5ttq93m4ngrz6uw20tgv0jskmmvgv9y0e40wqdq2f38xy6t5wvxqzjccqpjrzjqw6lfdpjecp4d5t0gxk5khkrzfejjxyxtxg5exqsd95py6rhwwh72rpgrgqq3hcqqgqqqqlgqqqqqqgq9q9qxpqysgq9szuwpy2kd7ksk9vsgdnef9z0pdzdermcya50dd7ncgemzzlqptyukew6zd
let amount = decodeInvoice.amount
let memo = decodeInvoice.description
try! await lnbits.payInvoice(invoice: "lnbc210n1pjd62g3sp5pwlfye29mk6mmsxzhj8w3cvq4va3tu2uwj2klwjqpguzhw67x38qpp5upej4ls9ytz7ard5ttq93m4ngrz6uw20tgv0jskmmvgv9y0e40wqdq2f38xy6t5wvxqzjccqpjrzjqw6lfdpjecp4d5t0gxk5khkrzfejjxyxtxg5exqsd95py6rhwwh72rpgrgqq3hcqqgqqqqlgqqqqqqgq9q9qxpqysgq9szuwpy2kd7ksk9vsgdnef9z0pdzdermcya50dd7ncgemzzlqptyukew6zd2m0ynan6shxv0s02qxvgzkapdfvps59vzx550hul6g0gp0937wp")
let balance = try await lnbits.getBalance()
The balance is in sats.
let name = try await lnbits.getName()
let txs = try await lnbits.getTXs()
try await lnbits.changeName(name: "Wallet")
let lnurl = try await lnbits.createLNURLPayLink()
let link = lnurl.lnurl
let lnurls = try await lnbits.getPayLinks()
let links = lnurls.map { lnurl in
lnurl.lnurl
}
let lnurl = try await lnbits.decodeLNURL(lnurl: "LNURLBITCOINISAWESOME")
switch lnurl.kind {
case .pay:
// LNURL Pay
case .withdraw:
// LNURL Withdraw
case .auth:
// LNURL Auth
}
try await lnbits.payLNURL(lnurl: "LNURLBITCOINISAWESOME", amount: 21)
let lnurl = try await lnbits.createLNURLWithdraw()
let link = lnurl.lnurl
let lnurl = try await lnbits.getLNURLWithdraws()
let a = lnurl.map { i in
i.lnurl
}
try! await lnbits.withdrawFromLNURLWithdraw(lnurl: "LNURLBITCOINISAWESOME")
This function automaticlly withdraws the highest amount possible. But you can also set an amount.
try! await lnbits.withdrawFromLNURLWithdraw(lnurl: "LNURLBITCOINISAWESOME", amount: 21)
try await lnbits.deleteLNURLPay(id: "BTC21M")
The ID is in the LNURLPay Object.
let lnurl = try await lnbits.createLNURLPayLink()
try await lnbits.deleteLNURLPay(id: lnurl.id)
try await lnbits.deleteLNURLWithdraw(id: "BTC21M")
try await lnbits.lnurlAuth(lnurl: "LNURLLOGINWITHLIGHTNING")
do {
// Code
}catch LNBitsError.error(let error) {
print(error)
}
let swap = try await lnbits.createSubMarineSwap(amount: 100000, refundAddress: "bc1qbitcoinfixesthis")
Min 50000 sats per Swap.
let swaps = try await lnbits.getSubMarineSwaps()
try await lnbits.refundSubMarineSwap(swapID: "mySwapID")
let swap = try await lnbitscreateReversedSubMarineSwap(amount: 100000, onChainAddress: "bc1qbitcoinfixesthis")
let swap = try await lnbits.getReversedSubMarineSwaps()