The official .NET SDK for ln.bot — Bitcoin for AI Agents.
Give your AI agents, apps, and services access to Bitcoin over the Lightning Network. Create wallets, send and receive sats, and get real-time payment notifications.
using LnBot;
using LnBot.Models;
using var client = new LnBotClient("key_...");
var invoice = await client.Invoices.CreateAsync(new CreateInvoiceRequest
{
Amount = 1000,
Memo = "Coffee",
});ln.bot also ships a TypeScript SDK, Python SDK, Go SDK, Rust SDK, CLI, and MCP server.
dotnet add package LnBotusing LnBot;
using LnBot.Models;
using var client = new LnBotClient();
var wallet = await client.Wallets.CreateAsync(new CreateWalletRequest
{
Name = "my-agent",
});
Console.WriteLine(wallet.PrimaryKey);using var client = new LnBotClient(wallet.PrimaryKey);
var invoice = await client.Invoices.CreateAsync(new CreateInvoiceRequest
{
Amount = 1000,
Memo = "Payment for task #42",
});
Console.WriteLine(invoice.Bolt11);await foreach (var evt in client.Invoices.WatchAsync(invoice.Number))
{
if (evt.Event == "settled")
{
Console.WriteLine("Paid!");
break;
}
}var payment = await client.Payments.CreateAsync(new CreatePaymentRequest
{
Target = "alice@ln.bot",
Amount = 500,
});var current = await client.Wallets.CurrentAsync();
Console.WriteLine($"{current.Available} sats available");using LnBot.Exceptions;
try
{
var wallet = await client.Wallets.CurrentAsync();
}
catch (NotFoundException ex)
{
Console.WriteLine($"Not found: {ex.Message}");
}
catch (BadRequestException ex)
{
Console.WriteLine($"Bad request: {ex.Message}");
}
catch (ConflictException ex)
{
Console.WriteLine($"Conflict: {ex.Message}");
}
catch (LnBotException ex)
{
Console.WriteLine($"API error {ex.StatusCode}: {ex.Message}");
}using var client = new LnBotClient("key_...", new LnBotClientOptions
{
BaseUrl = "https://api.ln.bot",
Timeout = TimeSpan.FromSeconds(30),
});Or bring your own HttpClient:
var httpClient = new HttpClient();
using var client = new LnBotClient("key_...", new LnBotClientOptions
{
HttpClient = httpClient,
});// Create a challenge (server side)
var challenge = await client.L402.CreateChallengeAsync(new CreateL402ChallengeRequest
{
Amount = 100,
Description = "API access",
ExpirySeconds = 3600,
});
// Pay the challenge (client side)
var result = await client.L402.PayAsync(new PayL402Request
{
WwwAuthenticate = challenge.WwwAuthenticate,
});
// Verify a token (server side, stateless)
var v = await client.L402.VerifyAsync(new VerifyL402Request
{
Authorization = result.Authorization!,
});- Zero dependencies —
System.Net.Http+System.Text.Jsononly - Async-first — every method returns
Task<T>withCancellationTokensupport - Typed exceptions —
BadRequestException,NotFoundException,ConflictException,UnauthorizedException,ForbiddenException - SSE support —
WatchAsyncreturnsIAsyncEnumerable<T>for real-time events - Nullable reference types — fully annotated
- .NET 8.0+
- Get your API key at ln.bot
- ln.bot — website
- Documentation
- GitHub
- NuGet
- TypeScript SDK · npm
- Python SDK · pypi
- Go SDK · pkg.go.dev
- Rust SDK · crates.io · docs.rs
MIT