LnBot.L402.AspNetCore
0.2.0
dotnet add package LnBot.L402.AspNetCore --version 0.2.0
NuGet\Install-Package LnBot.L402.AspNetCore -Version 0.2.0
<PackageReference Include="LnBot.L402.AspNetCore" Version="0.2.0" />
<PackageVersion Include="LnBot.L402.AspNetCore" Version="0.2.0" />
<PackageReference Include="LnBot.L402.AspNetCore" />
paket add LnBot.L402.AspNetCore --version 0.2.0
#r "nuget: LnBot.L402.AspNetCore, 0.2.0"
#:package LnBot.L402.AspNetCore@0.2.0
#addin nuget:?package=LnBot.L402.AspNetCore&version=0.2.0
#tool nuget:?package=LnBot.L402.AspNetCore&version=0.2.0
LnBot.L402.AspNetCore
L402 Lightning payment middleware for ASP.NET Core — paywall any API in one line. Built on ln.bot.
Protect ASP.NET Core routes behind L402 paywalls with middleware, [L402] attributes, or endpoint filters. Includes the LnBot.L402 client package.
What is L402?
L402 is a protocol built on HTTP 402 Payment Required. It enables machine-to-machine micropayments over the Lightning Network — ideal for API monetization, AI agent tool access, and pay-per-request data feeds.
Install
dotnet add package LnBot.L402.AspNetCore
This includes the client package (LnBot.L402) — no need to install both.
Quick Start
Middleware pipeline
using LnBot;
using LnBot.L402;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton(new LnBotClient("key_..."));
var app = builder.Build();
app.UseL402Paywall("/api/premium", new L402Options
{
Price = 10,
Description = "API access",
});
app.MapGet("/api/premium/data", () => Results.Ok(new { data = "premium content" }));
app.MapGet("/api/free/health", () => Results.Ok(new { status = "ok" }));
app.Run();
Controller attribute
using LnBot.L402;
[ApiController]
[Route("api/[controller]")]
public class WeatherController : ControllerBase
{
[L402(Price = 50, Description = "Weather forecast")]
[HttpGet("forecast")]
public IActionResult GetForecast()
=> Ok(new { forecast = "sunny" });
}
Minimal API endpoint filter
app.MapGet("/api/premium/data", () => Results.Ok(new { data = "premium" }))
.AddEndpointFilter(new L402EndpointFilter(price: 10, description: "API access"));
Dynamic pricing
app.UseL402Paywall("/api/dynamic", new L402Options
{
PriceFactory = context =>
{
if (context.Request.Path.StartsWithSegments("/api/dynamic/bulk"))
return Task.FromResult(50);
return Task.FromResult(5);
}
});
How It Works
The middleware makes two SDK calls:
client.L402.CreateChallengeAsync()— creates an invoice + macaroon when a client needs to payclient.L402.VerifyAsync()— verifies an L402 authorization token when a client presents one
All L402 logic — macaroon creation, signature verification, preimage checking — lives in the ln.bot API. Zero crypto dependencies.
Requirements
- .NET 8+
- An ln.bot API key — create a wallet to get one
Related
LnBot.L402— Client-side auto-pay handlerLnBot— The .NET SDK this package is built on@lnbot/l402— TypeScript equivalent
Links
- ln.bot — website
- Documentation
- L402 specification
- GitHub
License
MIT
| Product | Versions 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 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 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. |
-
net8.0
- LnBot.L402 (>= 0.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.