dotnet add package Kukks.Lightning.LNDhub --version 1.0.20
NuGet\Install-Package Kukks.Lightning.LNDhub -Version 1.0.20
<PackageReference Include="Kukks.Lightning.LNDhub" Version="1.0.20" />
paket add Kukks.Lightning.LNDhub --version 1.0.20
#r "nuget: Kukks.Lightning.LNDhub, 1.0.20"
// Install Kukks.Lightning.LNDhub as a Cake Addin #addin nuget:?package=Kukks.Lightning.LNDhub&version=1.0.20 // Install Kukks.Lightning.LNDhub as a Cake Tool #tool nuget:?package=Kukks.Lightning.LNDhub&version=1.0.20
A C# library for Lightning Network clients
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.Commoncontains the common abstractions shared between those implementation.
LightningClientFactorywhich can convert a connection string to an instance of
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.Allsuper package which reference all the others
BTCPayServer.Lightning.Commonexposes common classes and
BTCPayServer.Lightning.LNDexposes easy to use LND clients
BTCPayServer.Lightning.CLightningexposes easy to use clightning clients
BTCPayServer.Lightning.Chargeexposes easy to use Charge clients
BTCPayServer.Lightning.Eclairexposes easy to use Eclair clients
BTCPayServer.Lightning.LNbankexposes easy to use LNbank clients
BTCPayServer.Lightning.LNDhubexposes easy to use LNDhub clients
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, Charge, CLightning)
- 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
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.
connectionString encapsulates the necessary information BTCPay needs to connect to your Lightning node, we currently support:
clightningvia TCP or unix domain socket connection
lightning chargevia HTTPS
LNDvia the REST proxy
Eclairvia their new REST API
LNbankvia REST API
LNDhubvia their REST API
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.
Unless the LND certificate is trusted by your machine you need to set the server authentication scheme for LND by specifying one of:
certthumbprint are equivalent in terms of security but differ in their practical usage.
certfilepath reads a file on your file system so unless you set up some kind of file syncing you can not use it for remote connections.
The advantage is that if the certificate is updated (and synced in case of a remote machine) no more reconfiguration is required for RPC connections to continue to work.
It is therefore the recommended option if you can use it.
certthumbprint to connect to your LND node can be obtained through this command line:
openssl x509 -noout -fingerprint -sha256 -in /root/.lnd/tls.cert | sed -e 's/.*=//;s/://g'
allowinsecure=true just blindly accepts any server connection and is therefore not secure unless used in tightly controlled environments.
E.g. host is the same machine or is accessed over an encrypted tunnel, assuming no untrusted entities can bind the specified port.
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.
Using implementation specific class
If you want to leverage specific lightning network implementation, either instanciate directly
CLightningClient, or cast the
ILightningClient object returned by
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
|Product||Versions Compatible and additional computed target framework versions.|
|.NET||net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.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.|
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.