BTCPayServer.Lightning.Common 1.8.0

dotnet add package BTCPayServer.Lightning.Common --version 1.8.0
                    
NuGet\Install-Package BTCPayServer.Lightning.Common -Version 1.8.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BTCPayServer.Lightning.Common" Version="1.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BTCPayServer.Lightning.Common" Version="1.8.0" />
                    
Directory.Packages.props
<PackageReference Include="BTCPayServer.Lightning.Common" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BTCPayServer.Lightning.Common --version 1.8.0
                    
#r "nuget: BTCPayServer.Lightning.Common, 1.8.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BTCPayServer.Lightning.Common@1.8.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BTCPayServer.Lightning.Common&version=1.8.0
                    
Install as a Cake Addin
#tool nuget:?package=BTCPayServer.Lightning.Common&version=1.8.0
                    
Install as a Cake Tool

CI

A C# library for Lightning Network clients

Introduction

This library is meant to facilitate the development of Lightning Network based apps written in C#. Its main goal isn't to perfectly implement client API of all lightning node implementation, but to provide a common abstraction that can be used to support many implementations at once.

The most important packages are:

  • BTCPayServer.Lightning.Common contains the common abstractions shared between those implementation.
  • BTCPayServer.Lightning.All contains LightningClientFactory which can convert a connection string to an instance of ILightningClient.

If your app depends on ILightningClient directly, you will be able to support those different lightning implementations out of the box.

Here is a description of all packages:

  • BTCPayServer.Lightning.All super package which reference all the others NuGet
  • BTCPayServer.Lightning.Common exposes common classes and ILightningClient NuGet
  • BTCPayServer.Lightning.LND exposes easy to use LND clients NuGet
  • BTCPayServer.Lightning.CLightning exposes easy to use clightning clients NuGet
  • BTCPayServer.Lightning.Eclair exposes easy to use Eclair clients NuGet
  • BTCPayServer.Lightning.LNDhub exposes easy to use LNDhub clients NuGet

If you develop an app, we advise you to reference BTCPayServer.Lightning.All NuGet.

If you develop a library, we advise you to reference BTCPayServer.Lightning.Common NuGet.

You can also use our BOLT11PaymentRequest to parse BOLT11 invoices. (See example).

How to use

Click on the nuget button of the package interesting you, and follow the instruction to add it to your project. For .NET Core Apps, you need to enter this in your project's folder:

dotnet add package BTCPayServer.Lightning.All

You have two ways to use this library:

  • Either you want your code to works with all lightning implementation (right now LND, CLightning, Eclair, LNDHub, Phoenixd)
  • Or you want your code to work on a particular lightning implementation

Using the generic interface

This is done by using LightningClientFactory and the common interface ILightningClient.

string connectionString = "...";
ILightningClientFactory factory = new LightningClientFactory(Network.Main);
ILightningClient client = factory.Create(connectionString);
LightningInvoice invoice = await client.CreateInvoice(10000, "CanCreateInvoice", TimeSpan.FromMinutes(5));

ILightningClient is an interface which abstract the underlying implementation with a common interface.

The connectionString encapsulates the necessary information BTCPay needs to connect to your Lightning node, we currently support:

  • clightning via TCP or unix domain socket connection, or via clnrest with a rune
  • LND via the REST proxy
  • Eclair via their new REST API
  • LNDhub via their REST API
Examples
  • type=clightning;server=unix://root/.lightning/lightning-rpc
  • type=clightning;server=tcp://1.1.1.1:27743/
  • type=clightning;server=https://127.0.0.1:3010/;rune=tU-RLjMiDpY2U0o3W1oFowar36RFGpWloPbW9-RuZdo9MA==
  • type=clightning;server=https://127.0.0.1:3010/;runefilepath=/var/lib/btcpayserver/clightning.rune
  • type=clightning;server=http://10.10.0.2:3010/;rune=tU-RLjMiDpY2U0o3W1oFowar36RFGpWloPbW9-RuZdo9MA==
  • type=lnd-rest;server=http://mylnd:8080/;macaroonfilepath=/root/.lnd/invoice.macaroon
  • type=lnd-rest;server=https://mylnd:8080/;macaroon=abef263adfe...
  • type=lnd-rest;server=https://mylnd:8080/;macaroonfilepath=/root/.lnd/invoice.macaroon
  • type=eclair;server=http://127.0.0.1:4570;password=eclairpass
  • type=eclair;server=http://127.0.0.1:4570;password=eclairpass;bitcoin-host=bitcoin.host;bitcoin-auth=btcpass
  • type=lndhub;server=https://login:password@lndhub.io
Eclair notes

Note that bitcoin-host and bitcoin-auth are optional, only useful if you want to call ILightningClient.GetDepositAddress on Eclair. We expect this won't be needed in the future.

Core Lightning notes

An http:// or https:// server connects through the clnrest plugin. Use the root URL of clnrest and provide rune or runefilepath. Core Lightning 24.11 or newer is required.

A rune can limit what BTCPay Server may do. For receiving payments:

lightning-cli -k createrune restrictions='[["method=getinfo","method=invoice","method=listinvoices","method=waitanyinvoice","method=delinvoice","method=listfunds","method=listpeerchannels"],["method/delinvoice","pnamestatus=unpaid"]]'

Paying invoices also needs xpay and listpays. To rotate a file-based rune, replace the file and revoke the old rune.

Configure TLS validation and proxies on the supplied HttpClient handler; legacy TLS connection-string options are ignored. Self-signed certificates require platform trust or caller-configured validation. Use plain HTTP only in tightly controlled environments. Do not let untrusted users set runefilepath, since its contents are sent to the configured server. An injected HttpClient must not follow redirects, to avoid leaking the rune.

LND notes

LND uses the supplied HttpClient for HTTP requests and, on .NET 7 or later, WebSocket connections. Configure certificate validation, certificate pinning, proxies, and any insecure TLS behavior on that client's HTTP handler. Without a supplied client, normal platform HTTP/TLS defaults apply. Self-signed certificates must be trusted by the platform or explicitly handled by the caller's HTTP handler.

Legacy TLS connection-string options are accepted but ignored; they do not bypass certificate validation. Plain HTTP endpoints are accepted, but should only be used in tightly controlled environments, such as a local connection or an encrypted tunnel. The netstandard2.0 WebSocket API cannot use the supplied HttpClient and uses platform defaults instead.

LNDhub notes

You can also use the lndhub:// URL, which can be retrieved e.g. from the BlueWallet Export/Backup screen. The library turns it into the expected type=lndhub connection string format. HTTP and HTTPS endpoints are accepted without a connection-string opt-in; legacy TLS options are ignored. Configure transport security on the supplied HttpClient handler, and use plain HTTP only in tightly controlled environments.

Using implementation specific class

If you want to leverage specific lightning network implementation, either instanciate directly LndClient, CLightningClient, or EclairLightningClient, or cast the ILightningClient object returned by LightningClientFactory.

How to test

You first need to run all the dependencies with docker-compose:

cd tests
docker-compose up

Then you can run and debug the tests with Visual Studio or Visual Studio Code.

If you want to use command line:

cd tests
dotnet test

Licence

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (18)

Showing the top 5 NuGet packages that depend on BTCPayServer.Lightning.Common:

Package Downloads
LNURL

LNURL protocol implementation in .NET Core

BTCPayServer.Lightning.CLightning

Client library for c-lightning to build Lightning Network Apps in C#.

BTCPayServer.Lightning.LND

Client library for LND to build Lightning Network Apps in C#.

BTCPayServer.Lightning.Eclair

Client library for Eclair to build Lightning Network Apps in C#.

BTCPayServer.Lightning.LNDhub

Client library for BlueWallet LNDhub to build Lightning Network Apps in C#.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on BTCPayServer.Lightning.Common:

Repository Stars
btcpayserver/btcpayserver
Accept Bitcoin payments. Free, open-source & self-hosted, Bitcoin payment processor.
v0l/void.cat
Free file hosting website
Version Downloads Last Updated
1.8.0 490 11/24/2026
1.7.5 6,786 10/29/2026
1.7.4 6,247 10/5/2026
1.7.3 4,293 9/17/2026
1.7.2 7,881 8/12/2026
1.7.1 9,860 6/19/2026
1.7.0 1,595 6/9/2026
1.5.3 15,313 4/20/2026
1.5.2 65,621 11/30/2024
1.5.1 185,592 11/21/2023
1.5.0 11,223 10/19/2023
1.3.21 84,155 1/10/2023
1.3.20 2,227 1/6/2023
1.3.19 2,623 12/23/2022
1.3.18 1,925 12/22/2022
1.3.17 6,528 12/7/2022
1.3.16 48,580 12/5/2022
1.3.15 28,412 10/31/2022
1.3.14 2,739 10/26/2022
1.3.13 4,833 9/26/2022
Loading failed