10 unstable releases (3 breaking)

0.4.2 Oct 28, 2024
0.4.1 Oct 18, 2024
0.3.0 Jun 21, 2024
0.2.2 May 21, 2024
0.1.0-alpha Apr 27, 2023

#1 in #bdk

Download history 267/week @ 2024-07-29 363/week @ 2024-08-05 335/week @ 2024-08-12 344/week @ 2024-08-19 310/week @ 2024-08-26 188/week @ 2024-09-02 237/week @ 2024-09-09 337/week @ 2024-09-16 402/week @ 2024-09-23 204/week @ 2024-09-30 146/week @ 2024-10-07 554/week @ 2024-10-14 638/week @ 2024-10-21 593/week @ 2024-10-28 645/week @ 2024-11-04 544/week @ 2024-11-11

2,455 downloads per month

MIT/Apache

1MB
18K SLoC

Rust 11K SLoC // 0.0% comments Swift 5.5K SLoC // 0.1% comments Kotlin 531 SLoC // 0.1% comments Python 239 SLoC // 0.0% comments Shell 168 SLoC // 0.1% comments Batch 142 SLoC Forge Config 11 SLoC

Contains (JAR file, 62KB) gradle-wrapper.jar, (JAR file, 62KB) gradle-wrapper.jar

LDK Node

Crate Documentation Maven Central Android Maven Central JVM Security Audit

A ready-to-go Lightning node library built using LDK and BDK.

LDK Node is a self-custodial Lightning node in library form. Its central goal is to provide a small, simple, and straightforward interface that enables users to easily set up and run a Lightning node with an integrated on-chain wallet. While minimalism is at its core, LDK Node aims to be sufficiently modular and configurable to be useful for a variety of use cases.

Getting Started

The primary abstraction of the library is the Node, which can be retrieved by setting up and configuring a Builder to your liking and calling one of the build methods. Node can then be controlled via commands such as start, stop, open_channel, send, etc.

use ldk_node::Builder;
use ldk_node::lightning_invoice::Bolt11Invoice;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Network;
use std::str::FromStr;

fn main() {
	let mut builder = Builder::new();
	builder.set_network(Network::Testnet);
	builder.set_chain_source_esplora("https://blockstream.info/testnet/api".to_string(), None);
	builder.set_gossip_source_rgs("https://rapidsync.lightningdevkit.org/testnet/snapshot".to_string());

	let node = builder.build().unwrap();

	node.start().unwrap();

	let funding_address = node.onchain_payment().new_address();

	// .. fund address ..

	let node_id = PublicKey::from_str("NODE_ID").unwrap();
	let node_addr = SocketAddress::from_str("IP_ADDR:PORT").unwrap();
	node.open_channel(node_id, node_addr, 10000, None, None).unwrap();

	let event = node.wait_next_event();
	println!("EVENT: {:?}", event);
	node.event_handled();

	let invoice = Bolt11Invoice::from_str("INVOICE_STR").unwrap();
	node.bolt11_payment().send(&invoice).unwrap();

	node.stop().unwrap();
}

Modularity

LDK Node currently comes with a decidedly opinionated set of design choices:

  • On-chain data is handled by the integrated BDK wallet.
  • Chain data may currently be sourced from the Bitcoin Core RPC interface or an Esplora server, while support for Electrum will follow soon.
  • Wallet and channel state may be persisted to an SQLite database, to file system, or to a custom back-end to be implemented by the user.
  • Gossip data may be sourced via Lightning's peer-to-peer network or the Rapid Gossip Sync protocol.
  • Entropy for the Lightning and on-chain wallets may be sourced from raw bytes or a BIP39 mnemonic. In addition, LDK Node offers the means to generate and persist the entropy bytes to disk.

Language Support

LDK Node itself is written in Rust and may therefore be natively added as a library dependency to any std Rust program. However, beyond its Rust API it also offers language bindings for Swift, Kotlin, and Python based on the UniFFI. Moreover, Flutter bindings are also available.

MSRV

The Minimum Supported Rust Version (MSRV) is currently 1.63.0.

Dependencies

~65MB
~1M SLoC