SlamLink.x402 1.0.0
SlamLink.x402
X402 blockchain micropayment protocol integration for ASP.NET Core applications.
Overview
SlamLink.x402 provides middleware and services for implementing the X402 payment protocol in ASP.NET Core applications. It enables blockchain-based micropayments with metered API access.
Features
- X402Middleware: Intercepts HTTP requests for payment verification and cost estimation
- Facilitator API Client: Refit-based HTTP client with Polly retry logic for communicating with X402 facilitators
- OpenAPI Schema Generation: Automatic X402 discovery protocol schema generation for your API endpoints
- Payment Verification: Validates payment proofs from X402 facilitator
- Cost Estimation: Returns SLAM token cost estimates for API calls
Installation
dotnet add package SlamLink.x402
Quick Start
1. Configure Services
builder.Services.AddX402(options =>
{
options.Network = "base-sepolia";
options.AssetDecimals = 16;
options.AssetContract = "0x036CbD...";
options.PayToAddress = "0x635159...";
options.FacilitatorUrl = "https://x402.org/facilitator";
});
2. Add Middleware
app.UseX402();
3. Configure Endpoints
The middleware automatically handles:
- Cost estimation requests (when
estimate_cost=truequery parameter is present) - Payment verification (validates X402 payment headers)
- 402 Payment Required responses
Configuration
Configure X402 options via:
- Environment variables
- appsettings.json
- Code-based configuration
Environment Variables
NETWORK=base-sepolia
ASSET_DECIMALS=16
ASSET_CONTRACT=0x036CbD...
PAY_TO_ADDRESS=0x635159...
FACILITATOR=https://x402.org/facilitator
appsettings.json
{
"X402": {
"Network": "base-sepolia",
"AssetDecimals": 16,
"AssetContract": "0x036CbD...",
"PayToAddress": "0x635159...",
"FacilitatorUrl": "https://x402.org/facilitator"
}
}
Types
The package includes all necessary types for X402 integration:
PaymentRequiredResponse: 402 response with payment requirementsVerifyRequest/VerifyResponse: Payment verification typesSettleRequest/SettleResponse: Settlement typesPaymentPayload: Payment proof payloadX402OutputSchema: OpenAPI schema types for X402 discovery
Requirements
- .NET 8.0 or later
- ASP.NET Core
Dependencies
- Refit: HTTP client library
- Polly: Resilience and retry policies
- BouncyCastle: Cryptography
- Newtonsoft.Json: JSON serialization
License
MIT
No packages depend on SlamLink.x402.
.NET 8.0
- HiNetCloud.Microsoft.AspNetCore.Http.Abstractions (>= 24.8.10.9)
- Microsoft.AspNetCore.Http.Extensions (>= 2.3.0)
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
- Microsoft.Extensions.Http (>= 9.0.9)
- Microsoft.Extensions.Http.Polly (>= 9.0.9)
- Newtonsoft.Json (>= 13.0.3)
- Polly (>= 8.3.1)
- Portable.BouncyCastle (>= 1.9.0)
- Refit (>= 8.0.0)
- Refit.HttpClientFactory (>= 8.0.0)
- Swashbuckle.AspNetCore (>= 9.0.6)
| Version | Downloads | Last updated |
|---|---|---|
| 1.0.0 | 10 | 12/01/2025 |