LDK Node is a ready-to-go Lightning node library built using LDK and BDK where developers can get a Lightning Node up and running quickly.
The goal of this post is to give a quick yet clear conceptual understanding of the steps to develop a native iOS Lightning wallet along with the associated Swift code.
Steps to developing a Lightning Wallet
Typical operations a Lightning wallet might do is send and receive Lightning transactions along with tracking the Lightning wallet balance, and we can accomplish this quite easily with LDK Node.
The steps to developing an iOS Lightning wallet with LDK Node v0.1.0 after adding the Swift Package to your Xcode project are:
Build & Start Node
Receive Sats
Open Channel
Send Payment
Build & Start Node
let builder = LDKNode.Builder()
builder.setNetwork(
network: .testnet
)
builder.setEsploraServer(
esploraServerUrl: "https://blockstream.info/testnet/api"
)
builder.setGossipSourceRgs(
rgsServerUrl:
"https://rapidsync.lightningdevkit.org/testnet/snapshot"
)
do {
let node = try builder.build()
try node.start()
} catch {
// catch errors thrown
}
The primary abstraction of the LDK Node library is the Node
, which can be created by setting up and configuring a Builder
and calling one of the build
methods.
In this code we create a Builder then set the:
network to Testnet
Esplora Server to use Blockstream’s esplora
Rapid Gossip Sync Source to LDK’s deployment
We will focus on receiving funds to open a channel and make a payment.
Let’s assume the rest of these lines of code in this guide are inside the do-catch code block from above.
Receive Sats
let fundingAddress = try node.newOnchainAddress()
This line of code lets us create a funding address where we can receive On Chain sats.
Open Channel
try node.connectOpenChannel(
nodeId: "NODE_ID",
address: "IP_ADDR:PORT",
channelAmountSats: 10000,
pushToCounterpartyMsat: nil,
channelConfig: nil,
announceChannel: false
)
Once we have received the On Chain sats to our funding address we can open a Lightning channel.
Send Payment
let invoice = "INVOICE_STR"
try node.sendPayment(invoice: invoice)
Now that the Lightning channel is open we can send sats by getting an invoice and sending a Lightning payment.
We can for real send a Lightning payment, go to Bitcoin Park to buy a LaCroix with Lightning using LDK Node!
Next Steps
This is a high level but specific example of developing a Lightning wallet for iOS using LDK Node, a library that makes it extremely easy for developers to build a Lightning iOS wallet.
It was a short guide because LDK Node really makes it easy to get going! For further understanding of LDK Node check out the blog post announcing LDK Node and the LDK Discord, and a full open source example LDK Node iOS wallet built in SwiftUI named Monday.