x402 0.0.2
See the version list below for details.
dotnet add package x402 --version 0.0.2
NuGet\Install-Package x402 -Version 0.0.2
<PackageReference Include="x402" Version="0.0.2" />
<PackageVersion Include="x402" Version="0.0.2" />
<PackageReference Include="x402" />
paket add x402 --version 0.0.2
#r "nuget: x402, 0.0.2"
#:package x402@0.0.2
#addin nuget:?package=x402&version=0.0.2
#tool nuget:?package=x402&version=0.0.2
x402-dotnet
x402 Payment Protocol implementation for .Net
Install the x402 package from NuGet:
Features:
- Add a x402 compatible paywall to any URL
- Handle payment settlement using a remote server
How to use?
Setup the Facilitator in Program.cs
// Add the facilitator in Program.cs
builder.Services.AddHttpClient<IFacilitatorClient, HttpFacilitatorClient>(client =>
{
client.BaseAddress = new Uri("https://localhost:7141"); // Address of your facilitator
});
// Use the MVC Attribute
// Use the Payment Required Attribute
[HttpGet]
[Route("protected")]
[PaymentRequired("1", "0x00..Asset..Address", "0xYourWalletAddressHere", "base-sepolia")]
public IActionResult Protected()
{
return Content("Protected");
}
Or use the Middleware to require payment for a list of URLs
// Add Middleware
var facilitator = app.Services.GetRequiredService<IFacilitatorClient>();
var paymentOptions = new x402.Models.PaymentMiddlewareOptions
{
Facilitator = facilitator,
DefaultPayToAddress = "0xYourWalletAddressHere", // Replace with your actual wallet address
DefaultNetwork = "base-sepolia",
PaymentRequirements = new Dictionary<string, x402.Models.PaymentRequirementsConfig>()
{
{ "/url-to-pay-for", new x402.Models.PaymentRequirementsConfig
{
Scheme = x402.Enums.PaymentScheme.Exact,
MaxAmountRequired = 1000000,
Asset = "0x......", // Contract address of asset
MimeType = "application/json"
}
}
},
};
app.UsePaymentMiddleware(paymentOptions);
Coinbase
To use the Coinbase Facilitator, install x402.Coinbase
// Add the Coinbase Config and Facilitator
builder.Services.Configure<CoinbaseOptions>(builder.Configuration.GetSection(nameof(CoinbaseOptions)));
builder.Services.AddHttpClient<IFacilitatorClient, CoinbaseFacilitatorClient>();
Add to appsettings.json:
"CoinbaseOptions": {
"ApiKeyId": "YOUR_COINBASE_API_KEY_ID",
"ApiKeySecret": "YOUR_COINBASE_API_KEY_SECRET"
}
Faciliators
List of facilitators you can use:
- https://api.cdp.coinbase.com/platform/v2/x402/ (Coinbase, requires API key)
- https://facilitator.payai.network
- https://facilitator.mogami.tech/
- https://facilitator.mcpay.tech (Proxy Faciliator)
Development
There is a sample website and mock Settlement server included.
- Start the Aspire project:
x402-dotnet.AppHost - Navigate to the sample website
https://localhost:7154/ - Use the
x402.SampleWeb.httpfor sample web requests
Tools
Useful tools when developing x402 solutions:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
-
net9.0
- Microsoft.AspNetCore.Http (>= 2.3.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
- Microsoft.Extensions.Http (>= 9.0.9)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on x402:
| Package | Downloads |
|---|---|
|
x402.Coinbase
x402 Payment Required Coinbase facilitator client for .net |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 126 | 1/9/2026 |
| 0.0.18 | 457 | 12/10/2025 |
| 0.0.17 | 193 | 12/5/2025 |
| 0.0.16 | 695 | 12/2/2025 |
| 0.0.15 | 445 | 11/18/2025 |
| 0.0.13 | 171 | 11/7/2025 |
| 0.0.12 | 167 | 11/1/2025 |
| 0.0.11 | 181 | 10/31/2025 |
| 0.0.10 | 213 | 10/29/2025 |
| 0.0.9 | 230 | 10/29/2025 |
| 0.0.8 | 189 | 10/24/2025 |
| 0.0.7 | 185 | 10/24/2025 |
| 0.0.6 | 201 | 10/22/2025 |
| 0.0.5 | 165 | 10/17/2025 |
| 0.0.4 | 207 | 10/8/2025 |
| 0.0.3 | 206 | 10/7/2025 |
| 0.0.2 | 207 | 10/6/2025 |
| 0.0.1 | 172 | 10/3/2025 |