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=true query 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 requirements
  • VerifyRequest/VerifyResponse: Payment verification types
  • SettleRequest/SettleResponse: Settlement types
  • PaymentPayload: Payment proof payload
  • X402OutputSchema: 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.

Version Downloads Last updated
1.0.0 10 12/01/2025