NLightning.Bolt11.Blazor 4.0.0

dotnet add package NLightning.Bolt11.Blazor --version 4.0.0
                    
NuGet\Install-Package NLightning.Bolt11.Blazor -Version 4.0.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="NLightning.Bolt11.Blazor" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NLightning.Bolt11.Blazor" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NLightning.Bolt11.Blazor" />
                    
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 NLightning.Bolt11.Blazor --version 4.0.0
                    
#r "nuget: NLightning.Bolt11.Blazor, 4.0.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 NLightning.Bolt11.Blazor@4.0.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=NLightning.Bolt11.Blazor&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NLightning.Bolt11.Blazor&version=4.0.0
                    
Install as a Cake Tool

NLightning.Bolt11

This library provides a decoder/encoder for the BOLT11 invoice format used in the Lightning Network. It can be used to decode and/or encode BOLT11 invoices.

Available Packages

We've decided to have 2 packages, one for desktop/server development, and one for Blazor WebAssembly development.

The reason behind this is that for a Blazor app running fully on the browser we don't have access to native libsodium.

Sample

A sample project using this project in a Blazor WebAssembly environment can be found here.

A live version of the sample can be found at bolt11.ipms.io

Usage

Follow the steps below to install and decode bolt11 invoices.

Installation

Install the package from NuGet:

# For the "standard" version of the package run
dotnet add package NLightning.Bolt11

# For the Blazor WebAssembly version run
dotnet add package NLightning.Bolt11.Blazor

Decoding

// add the using directive
using NLightning.Bolt11.Models;

// decode the invoice string
var invoice = Invoice.Decode(invoice_string);

// Get the properties from the invoice
Console.WriteLine("Here's a few props from the invoice:")
Console.WriteLine(invoice.Amount.MilliSatoshi);
Console.WriteLine(invoice.Amount.Satoshi);
Console.WriteLine(invoice.PaymentHash);
Console.WriteLine("A list with all the props can be found at: https://nlightning.ipms.io/api/NLightning.Bolts.BOLT11.Invoice.html#properties");

Decoding in Blazor Apps

Blazor apps need to initialize the CryptoProvider in order to load the needed js files. Add the following to your Program.cs file.

Initialize the CryptoProvider (libsodium.js)
// Add the using directive
using NLightning.Infrastructure.Crypto.Providers.JS;

// ...
// Your app code

// Initialize the Crypto Provider just before starting the server.
await BlazorCryptoProvider.InitializeBlazorCryptoProviderAsync();

await builder.Build().RunAsync();
Decode the invoice
@using NLightning.Bolt11.Models

<button @onclick="DecodeInvoice">Decode</button>
<br/>
@if (invoice != null)
{
    <p>Payment Hash: @invoice.PaymentHash</p>
    <p>Amount MilliSats: @invoice.Amount.MilliSatoshi</p>
    <p>Amount Sats: @invoice.Amount.Satoshi</p>
    <p>Amount BTC: @invoice.Amount</p>
    <p>Description: @invoice.Description</p>
}

@code{

    Invoice? invoice;
    
    void DecodeInvoice()
    {
        invoice = Invoice.Decode("lnbc1pndpjfppp5qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssp5qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqsdqq5243a4h29w7lm6g89hktd0qzfakevjp7hktskal5p69jxa6vyqw4s95577lltw0t6l9dhp7cfld9urkxfsucsxascnxdqmanrlklsqcp5nwzmf");
    }

}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 174 6/18/2025
3.0.1 162 5/21/2025
3.0.0 246 5/20/2025 3.0.0 is deprecated because it has critical bugs.
2.0.0 165 5/5/2025
1.0.0 173 4/28/2025
0.2.4 306 3/7/2025
0.2.3 128 2/25/2025
0.2.2 241 9/13/2024
0.2.1 181 9/12/2024 0.2.1 is deprecated because it has critical bugs.
0.2.0 168 9/12/2024 0.2.0 is deprecated because it has critical bugs.

Introduced a dedicated validation service and stricter field checks to improve invoice robustness, along with API consistency and null-safety enhancements.