This library is meant to facilitate the development of Lightning Network based apps written in C#. It is composed of 4 packages.
BTCPayServer.Lightning.All
super package which reference all the othersBTCPayServer.Lightning.LND
exposes easy to use LND clientsBTCPayServer.Lightning.CLightning
exposes easy to use clightning clientsBTCPayServer.Lightning.Charge
exposes easy to use Charge clientsBTCPayServer.Lightning.Eclair
exposes easy to use Eclair clientsBTCPayServer.Lightning.Ptarmigan
exposes easy to use Ptarmigan clientsBTCPayServer.Lightning.Common
exposes common classes andILightningClient
If you develop an app, we advise you to reference BTCPayServer.Lightning.All
.
If you develop a library, we advise you to reference BTCPayServer.Lightning.Common
.
You can also use our BOLT11PaymentRequest
to parse BOLT11 invoices. (See example).
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
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 connectionlightning charge
via HTTPSLND
via the REST proxyEclair
via their new REST API
type
=clightning;server
=unix://root/.lightning/lightning-rpctype
=clightning;server
=tcp://1.1.1.1:27743/type
=lnd-rest;server
=http://mylnd:8080/;macaroonfilepath
=/root/.lnd/admin.macaroon;allowinsecure=truetype
=lnd-rest;server
=https://mylnd:8080/;macaroon
=abef263adfe...type
=lnd-rest;server
=https://mylnd:8080/;macaroon
=abef263adfe...;certthumbprint
=abef263adfe...type
=charge;server
=https://charge:8080/;api-token
=myapitoken...type
=charge;server
=https://charge:8080/;cookiefilepath
=/path/to/cookie...type
=eclair;server
=http://127.0.0.1:4570;password
=eclairpass;bitcoin-host
=127.0.0.1:37393;bitcoin-auth
=user:pass
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.
Note that the certthumbprint
to connect to your LND node can be obtained through this command line:
openssl x509 -noout -fingerprint -sha256 -inform pem -in /root/.lnd/tls.cert
You can omit certthumprint
if you the certificate is trusted by your machine
You can set allowinsecure
to true
if your LND REST server is using HTTP or HTTPS with an untrusted certificate which you don't know the certthumprint
.
If you want to leverage specific lightning network implementation, either instanciate directly ChargeClient
, LndClient
or CLightningClient
, or cast the ILightningClient
object returned by LightningClientFactory
.
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