OpenReceive 0.6.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package OpenReceive --version 0.6.4
                    
NuGet\Install-Package OpenReceive -Version 0.6.4
                    
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="OpenReceive" Version="0.6.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenReceive" Version="0.6.4" />
                    
Directory.Packages.props
<PackageReference Include="OpenReceive" />
                    
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 OpenReceive --version 0.6.4
                    
#r "nuget: OpenReceive, 0.6.4"
                    
#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 OpenReceive@0.6.4
                    
#: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=OpenReceive&version=0.6.4
                    
Install as a Cake Addin
#tool nuget:?package=OpenReceive&version=0.6.4
                    
Install as a Cake Tool

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 from LSC_URI_PRIMARY / LSC_URI_BACKUP.

Quickstart (ASP.NET Core)

  1. Route the openreceive commands, then scaffold:

    app.MapOpenReceive("/openreceive");
    if (await app.TryRunOpenReceiveCommandAsync(args)) return;
    
    dotnet run -- openreceive install
    

    It writes OpenReceiveHost.cs and the migration for the engine's two tables: an EF Core migration when the app has a DbContext, a SQL file otherwise. The statements come from the library, per dialect (PaymentsSchema.Statements(dialect), PaymentsSchema.DropStatements(dialect) for a Down()); PaymentsSchema.MigrateAsync(database) runs them in one call for scripts.

  2. 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 Core DbContext joins the settlement transaction with db.Database.SetDbConnection(settlement.Session.Connection) and db.Database.UseTransactionAsync(settlement.Session.Transaction). Implement IAfterPaid as well for work that must run after the commit (mail, events).

  3. Register:

    builder.Services.AddOpenReceive<OpenReceiveHost>(o =>
        o.UseConnection(_ => new SqlConnection(builder.Configuration.GetConnectionString("Shop"))));
    

    dotnet run -- openreceive doctor checks 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
0.6.6 0 11/29/2026
0.6.5 0 11/29/2026
0.6.4 0 11/29/2026