Xrpl.X402.AspNetCore 1.1.0

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

Xrpl.X402.AspNetCore

Server-side of x402 (HTTP-402) agentic payments for the XRP Ledger. Protect an ASP.NET Core endpoint so it requires an XRPL payment (XRP or RLUSD/IOU) before serving โ€” the t54 "XRPL exact scheme".

Pairs with the client package Xrpl.X402. Builds on the Xrpl SDK.

๐Ÿ“– Full documentation โ€” end-to-end flow (price โ†’ pay โ†’ receipt) with XRP and RLUSD/IOU examples: x402 Agentic Payments Guide ยท API reference.

What it adds

Type Role
RequirePayment(...) endpoint filter Returns 402 + PAYMENT-REQUIRED when no payment is presented; with a valid PAYMENT-SIGNATURE it verifies + settles, sets PAYMENT-RESPONSE, and runs your handler.
IX402Facilitator Abstraction that verifies a signed payment and settles it on-ledger.
LedgerSettlingFacilitator(IXrplClient) Settles locally against your own connected node (SubmitRequestAndWait, waits for tesSUCCESS). An outcome it cannot tell is answered as settlement_unknown with the transaction hash, to reconcile.
ISettledPaymentStore / InMemorySettledPaymentStore Record of settled transaction hashes, so one signed payment unlocks the resource once. The in-memory default covers one process; several instances need a shared store.
AddLedgerSettlingFacilitator() Registers LedgerSettlingFacilitator as the singleton IX402Facilitator over the registered IXrplClient, with the in-memory store unless an ISettledPaymentStore is registered first.
T54Facilitator(HttpClient, baseUrl) Delegates verify + settle to an external t54 facilitator (POST /verify, /settle). Verified live against the t54 testnet facilitator.

Usage

using Xrpl.X402.AspNetCore;
using Xrpl.X402.Wire;

IXrplClient xrpl = /* your connected IXrplClient */;
// One facilitator for every endpoint: its record of settled payments is what stops a replay.
// Separate instances keep separate records, so a blob paid on one endpoint would pass another.
IX402Facilitator facilitator = new LedgerSettlingFacilitator(xrpl);
// or: IX402Facilitator facilitator = new T54Facilitator(new HttpClient());

app.MapGet("/paid", () => "premium content")
   .RequirePayment(facilitator, ctx => new PaymentRequirement
   {
       Scheme = "exact",
       Network = "xrpl:1",
       Asset = "XRP",
       PayTo = "rYourMerchantAddress...",
       Amount = "1000000",            // 1 XRP in drops
       MaxTimeoutSeconds = 600,
       Extra =
       {
           ["invoiceId"] = JsonSerializer.SerializeToElement("inv-123"),
           ["sourceTag"] = JsonSerializer.SerializeToElement(804681468) // t54 enforces SourceTag
       }
   });

Without a PAYMENT-SIGNATURE the endpoint returns 402 + the PAYMENT-REQUIRED challenge. With a valid signature, the facilitator verifies the payment, settles the transaction, sets PAYMENT-RESPONSE, and your handler runs. Implement IX402Facilitator for any other facilitator.

What LedgerSettlingFacilitator refuses

errorReason When
invalid_transaction_type The blob is not a Payment (a CheckCreate or EscrowCreate has a Destination too).
invalid_destination Destination is not payTo, or DestinationTag is not the tag of an X-address payTo or extra.destinationTag.
invalid_partial_payment tfPartialPayment is set: such a payment can deliver any fraction of Amount.
invalid_asset Amount is not the required asset: XRP drops for XRP, otherwise the currency (as text or 40 hex digits) issued by extra.issuer.
invalid_amount Amount is not exactly the required amount.
invalid_invoice_id extra.invoiceId is set and the transaction carries neither InvoiceID = SHA-256 of it nor a memo whose MemoData is it in hex.
invalid_last_ledger_sequence No LastLedgerSequence, which leaves the blob valid forever, or one further than maxTimeoutSeconds allows (at 3 seconds a ledger, at least 20 ledgers, plus 10 for a payer whose node is ahead of the facilitator's).
payment_expired LastLedgerSequence is already validated, so only a replay of an earlier settlement could succeed.
duplicate_payment The transaction hash is already settled, or is being settled.
delivered_amount_mismatch The payment validated, but the metadata's delivered_amount is short of the requirement or in another asset.

The payment is checked against the endpoint's own requirement: RequirePayment compares the client's accepted with it (including extra.issuer, extra.invoiceId and extra.destinationTag) and then hands the facilitator the server's copy. A caller that invokes a facilitator directly must do the same.

Resubmitting a validated blob makes the node report the original tesSUCCESS, so the facilitator keeps the hash of every payment it settled until the payment's window has passed. Keep one facilitator for the application, or register it through AddLedgerSettlingFacilitator():

builder.Services.AddSingleton<IXrplClient>(xrpl);
// Several instances behind a load balancer: register a shared ISettledPaymentStore here first.
// A store serves one network; mainnet and testnet need separate ones.
builder.Services.AddLedgerSettlingFacilitator();

IX402Facilitator facilitator = app.Services.GetRequiredService<IX402Facilitator>();

See the Xrpl.X402 README for the full wire format, client usage, security model, and t54 interop notes.

License

Apache-2.0. Part of XrplCSharp.

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 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

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
1.1.0 0 10/25/2026
1.0.1 101 10/5/2026
1.0.0 165 6/24/2026