x402.Client 0.0.7

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

x402-dotnet

x402 payments enabled
x402 Payment Protocol implementation for .Net

x402 on the server

Install the x402 packages from NuGet:

Features:

  • Add an x402-compatible paywall to any URL
  • Easily use an attribute to handle payments for your API methods
  • Add URLs that require payment using the middleware
  • Support advanced scenarios by calling the X402Handler in your API controller
  • Handle payment settlement using any remote facilitator
  • Optionally use the Coinbase facilitator (with API key)
  • Extensible TokenInfoProvider that fills in network and coin data based on the asset address

x402 enabled HttpClient

Install the x402.Client.EVM package from NuGet:

Features:

  • Transparant access x402-protected resources
  • Fully HttpClient compatible
  • Pay using the embedded EVM compatible wallet (Ethereum / Base)
  • Set allowances per request or globally
  • X402.Client.ConsoleSample sample application included

How to use?

Register the x402 services and facilitator in Program.cs:

// Use the default HttpFacilitator
builder.Services.AddX402().WithHttpFacilitator(facilitatorUrl);

Use the PaymentRequired Attribute

// Use the Payment Required Attribute
[HttpGet]
[Route("protected")]
[PaymentRequired("1000", "0x036CbD53842c5426634e7929541eC2318f3dCF7e", "0xYourAddressHere")]
public SampleResult Protected()
{
    return new SampleResult { Title = "Protected by PaymentRequired Attribute" };
}

Directly in an API Controller (for more control)

public ResourceController(X402Handler x402Handler)
{
    this.x402Handler = x402Handler;
}

[HttpGet]
[Route("dynamic")]
public async Task<SampleResult?> Dynamic(string amount)
{
    var x402Result = await x402Handler.HandleX402Async(this.HttpContext, facilitator, fullUrl,
        new PaymentRequirementsBasic
        {
            Asset = "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
            Description = "Dynamic payment",
            MaxAmountRequired = amount,
            PayTo = "0x7D95514aEd9f13Aa89C8e5Ed9c29D08E8E9BfA37",
        });

    if (!x402Result.CanContinueRequest)
    {
        return null; // Response already written by HandleX402Async, so just exit
    }

    //Continue with the request
}

Or use the PaymentMiddleware to require payment for a list of URLs

// Add Middleware
var paymentOptions = new PaymentMiddlewareOptions
{
    PaymentRequirements = new Dictionary<string, PaymentRequirementsConfig>()
    {
        {  "/resource/middleware", new PaymentRequirementsConfig
            {
                PaymentRequirements = new PaymentRequirementsBasic {
                    MaxAmountRequired = "1000",
                    Asset = "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
                    MimeType = "application/json",
                    Description = "Payment Required",
                    Discoverable = true,
                    PayTo = "0x7D95514aEd9f13Aa89C8e5Ed9c29D08E8E9BfA37", // Replace with your actual wallet address
                }
            }
        }
    },
};

app.UsePaymentMiddleware(paymentOptions);

Coinbase Facilitator

To use the Coinbase Facilitator, install x402.Coinbase

// Add the Coinbase Config and Facilitator
builder.Services.AddX402().WithCoinbaseFacilitator(builder.Configuration);

Add to appsettings.json:

 "CoinbaseOptions": {
   "ApiKeyId": "YOUR_COINBASE_API_KEY_ID",
   "ApiKeySecret": "YOUR_COINBASE_API_KEY_SECRET"
 }

x402 HttpClient

// Fixed private key (32 bytes hex)
var wallet = new EVMWallet("0x0123454242abcdef0123456789abcdef0123456789abcdef0123456789abcdef", chainId) //84532UL = base-sepolia
{
    IgnoreAllowances = true
};

var handler = new PaymentRequiredHandler(wallet);

var client = new HttpClient(handler);
var response = await client.GetAsync("https://www.x402.org/protected");

Console.WriteLine($"Final: {(int)response.StatusCode} {response.ReasonPhrase}");

See X402.Client.ConsoleSample for a complete example.

How to test?

Follow these steps to test a x402 payment on the sample website hosted on Azure:

  • Get some USDC tokens on the base-sepolia network from the Coinbase Faucet
  • Use the x402 Debug Tool: https://proxy402.com/fetch
  • Enter an API endpoint from the test website, for example: https://x402-dotnet.azurewebsites.net/resource/middleware
  • Connect your wallet
  • Click Pay
  • Payment will complete and show the result: Protected by middleware

Facilitators

List of facilitators you can use:

View more facilitators and their status on https://x402dev.com

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 x402.SampleWeb.http for sample web requests

Contributions

Contributions are welcome. Fork this repository and send a pull request if you have something useful to add.

Useful tools when developing x402 solutions:

Product 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. 
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 x402.Client:

Package Downloads
x402.Client.EVM

x402 Payment Required Client implementation for .net

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 114 1/9/2026
0.0.18 451 12/10/2025
0.0.17 210 12/5/2025
0.0.16 687 12/2/2025
0.0.15 428 11/18/2025
0.0.14 130 11/7/2025
0.0.13 177 11/7/2025
0.0.12 175 11/1/2025
0.0.11 163 10/31/2025
0.0.10 207 10/29/2025
0.0.9 205 10/29/2025
0.0.8 163 10/24/2025
0.0.7 170 10/24/2025
0.0.6 193 10/22/2025
0.0.5 140 10/17/2025