OpenReceive 0.6.6
dotnet add package OpenReceive --version 0.6.6
NuGet\Install-Package OpenReceive -Version 0.6.6
<PackageReference Include="OpenReceive" Version="0.6.6" />
<PackageVersion Include="OpenReceive" Version="0.6.6" />
<PackageReference Include="OpenReceive" />
paket add OpenReceive --version 0.6.6
#r "nuget: OpenReceive, 0.6.6"
#:package OpenReceive@0.6.6
#addin nuget:?package=OpenReceive&version=0.6.6
#tool nuget:?package=OpenReceive&version=0.6.6
OpenReceive for .NET
Accept Lightning payments in a .NET app straight into your own wallet, with a
receive-only Nostr Wallet Connect (NWC) code. OpenReceive is the engine: it
keeps one payment-attempt row per invoice in your database, settles each
attempt once, and fulfills each order once through your own OnPaidAsync.
An ASP.NET Core app installs
OpenReceive.AspNetCore
instead, which brings this package and mounts the checkout routes:
dotnet add package OpenReceive.AspNetCore
OpenReceive also supports optional swaps from USDT, USDC, SOL, and ETH through a configured swap provider. The provider converts the payment to BTC over Lightning, which settles into the merchant's connected wallet. Available assets and networks depend on the provider; swaps are optional.
Quickstart: https://openreceive.org/guides/quickstart-aspnetcore.md. The engine also backs the BTCPay Server and nopCommerce plugins in the OpenReceive repository.
Requirements
- .NET 10 (
net10.0). - One of PostgreSQL (Npgsql), MySQL 8 / MariaDB (MySqlConnector), SQLite (Microsoft.Data.Sqlite) or SQL Server / Azure SQL (Microsoft.Data.SqlClient). The engine references no driver: you pass your own connection.
- A receive-only NWC code in
NWC_URI: https://openreceive.org/get_a_nwc_code_to_receive_payments. Optional swap providers come fromLSC_URI_PRIMARY/LSC_URI_BACKUP.
Quickstart (ASP.NET Core)
Route the
openreceivecommands, then scaffold:app.MapOpenReceive("/openreceive"); if (await app.TryRunOpenReceiveCommandAsync(args)) return;dotnet run -- openreceive installIt writes
OpenReceiveHost.csand the migration for the engine's two tables: an EF Core migration when the app has aDbContext, a SQL file otherwise. The statements come from the library, per dialect (PaymentsSchema.Statements(dialect),PaymentsSchema.DropStatements(dialect)for aDown());PaymentsSchema.MigrateAsync(database)runs them in one call for scripts.Implement the host contract: who may pay, what an order costs, and what happens when it is paid.
public sealed class OpenReceiveHost(ShopDb db) : IOpenReceiveHost { public Task<bool> AuthorizeAsync(AuthorizeContext context, CancellationToken ct) => db.IsOwnerAsync(context.Reference, context.Request, ct); // your ownership check public async Task<OpenReceivePrice?> AmountForAsync(string reference, CancellationToken ct) => await db.Orders.FindAsync([reference], ct) is { } order ? OpenReceivePrice.Of("USD", order.Total.ToString("0.00", CultureInfo.InvariantCulture), order.Title) : null; // Runs INSIDE the settlement transaction, once per order. public Task OnPaidAsync(PaymentSettlement settlement, CancellationToken ct) => settlement.Session!.ExecuteAsync( "UPDATE orders SET paid = 1 WHERE id = ? AND paid = 0", new object?[] { settlement.Reference }, ct); }Prices are decimal strings (or
OpenReceivePrice.OfSats), never binary floats. An EF CoreDbContextjoins the settlement transaction withdb.Database.SetDbConnection(settlement.Session.Connection)anddb.Database.UseTransactionAsync(settlement.Session.Transaction). ImplementIAfterPaidas well for work that must run after the commit (mail, events).Register:
builder.Services.AddOpenReceive<OpenReceiveHost>(o => o.UseConnection(_ => new SqlConnection(builder.Configuration.GetConnectionString("Shop"))));dotnet run -- openreceive doctorchecks the result.
MapOpenReceive serves exactly the routes in
spec/openapi/openreceive-http.v1.yaml:
POST checkouts/prepare, checkouts, payments/check, swaps/quote,
swaps, swaps/status, swaps/refunds and GET rates, for the shared
browser checkout. The server resolves every amount from AmountForAsync; a
payer-supplied amount is refused.
At startup the engine reads the wallet's capabilities and refuses to boot
when the connection advertises spend methods (pay_invoice and friends).
AllowSpendCapableWallet / OPENRECEIVE_ALLOW_SPEND_CAPABLE_NWC=true is the
explicit, not recommended, override.
How settlement is found
Every mounted payment route first runs one reconcile pass through a durable
gate row in openreceive_meta, shared by every instance of the app (at most
one real wallet scan every 3 to 12 seconds). payments/check is answered
from that pass or from the stored row. dotnet run -- openreceive notifications
runs the NWC-02 notifications listener and its periodic pass as its own
process (or set RunNotificationsWorker = true for a hosted service), and
openreceive reconcile is one pass for a cron job. An unpaid attempt is closed only by a complete wallet scan
at or after its expiry plus 900 seconds; a local clock never closes a row.
Options worth knowing
| Option | Default | Meaning |
|---|---|---|
PriceCurrencies |
USD |
Fiat currencies AmountForAsync may price in (live BTC price feed with fallback). |
RateLimiting |
off | Built-in per-IP limit on new invoices (new RateLimitingOptions(LimitPerHour: 60)). Put ForwardedHeaders in front behind a proxy. |
OpportunisticReconcile |
on | Turn off only when the notifications worker owns scanning. |
CacheWalletInfo |
on | Remembers the wallet info event in IDistributedCache / IMemoryCache. |
WalletClient |
NWC_URI | Tests pass OpenReceive.Testing.FakeWallet; FakeSwapProvider stands in for a swap provider. |
Without ASP.NET Core, compose Service.CreateAsync, SqlPaymentRepository
and Engine directly; engine.Router.HandleAsync takes a framework-free
request.
Storage notes
The tables have the same shape on every engine (Rails, PHP, Python), so a
database migrated by another engine works unchanged. Per dialect the
per-reference lock is pg_advisory_xact_lock (PostgreSQL), GET_LOCK
around the transaction (MySQL), BEGIN IMMEDIATE (SQLite) and
sp_getapplock owned by the transaction (SQL Server). On SQL Server the
reference, hash and client-IP columns are NVARCHAR with the binary
collation Latin1_General_100_BIN2, JSON is NVARCHAR(MAX) and timestamps
are DATETIME2(6) in UTC. See
https://openreceive.org/guides/storage.md for the attempt state machine.
Tests
npm run test:dotnet builds the .NET solution and runs this engine's suite
(packages/dotnet/OpenReceive.Tests) in the mcr.microsoft.com/dotnet/sdk:10.0
container, against SQLite plus throwaway PostgreSQL, MySQL and SQL Server
containers. No host SDK and no real wallet are needed.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- NNostr.Client (>= 0.0.55)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on OpenReceive:
| Package | Downloads |
|---|---|
|
OpenReceive.AspNetCore
Accept Bitcoin over Lightning in an ASP.NET Core app, paid straight into your own wallet with a receive-only NWC code, plus optional USDT, USDC, SOL and ETH payments that a swap provider converts to BTC over Lightning. AddOpenReceive and MapOpenReceive mount the checkout routes over payment rows in your own database; the openreceive doctor, install and reconcile commands run from your app. |
GitHub repositories
This package is not used by any popular GitHub repositories.