x402_core library

Core protocol definitions and interfaces for the x402 payment protocol.

Classes

AssetAmount
A concrete asset-based price.
FacilitatorClient
Interface for facilitator clients.
HttpFacilitatorClient
Money
A user-defined monetary price.
Network
Represents a CAIP-2 blockchain network identifier.
PaymentOption
Configuration for a single payment option.
PaymentPayload
The payload sent by the client in the payment-signature (or x-payment) header.
PaymentRequiredResponse
The structured response body returned by a server when it requires payment (HTTP 402).
PaymentRequirement
Represents a specific payment option offered by a server in a 402 response.
PaywallConfig
Paywall configuration for HTML responses.
Price
Base type for all resource prices.
ResourceConfig
Configuration for a protected resource.
ResourceInfo
Metadata about the digital resource being requested.
RouteConfig
Configuration for a protected route.
RoutePattern
Represents a type-safe route pattern with HTTP method and path.
SchemeClient
Interface for payment scheme clients (e.g., "exact", "stream")
SchemeServer
Defines how a specific payment scheme behaves on a given network.
SettleResponse
Response returned by a facilitator when settling a payment.
SignedPayment
A SignedPayment represents the final result of the signing process.
SupportedKind
A payment kind supported by a facilitator.
SupportedResponse
Describes supported payment kinds, extensions and signers.
TokenAmountNormalizer
Normalizes a decimal string into a fixed-precision token amount string.
VerifyResponse
Response returned by a facilitator when verifying a payment.
X402Client
A high-level HTTP client that automatically handles 402 Payment Required flows.
X402ResourceServer
Main entry point for protecting resources with x402 payments.
X402Signer
The interface every blockchain-specific package must implement to support signing x402 payment requirements.

Enums

HttpMethod
Represents an HTTP request method.

Constants

kDefaultFacilitatorUrl → const String
Default facilitator URL (testnet)
kPaymentHeader → const String
Legacy header for payment proof (optional)
kPaymentRequiredHeader → const String
Standard header for payment requirements in 402 response
kPaymentRequiredStatus → const int
HTTP status code for payment required
kPaymentResponseHeader → const String
Standard header for payment response in 402 response
kPaymentSignatureHeader → const String
Standard header for payment proof in request
kX402Version → const int
x402 protocol version

Typedefs

AuthHeaderFactory = Future<Map<String, Map<String, String>>> Function()
MoneyParser = Future<AssetAmount?> Function(String amount, Network network)
Signature for custom money parsers.
PaymentApprovalCallback = Future<bool> Function(PaymentRequirement requirement, ResourceInfo resource, X402Signer signer)
Callback invoked when a 402 Payment Required response is received, allowing the application to request user approval before a payment is signed and sent.
PaymentRoutes = Map<RoutePattern, RouteConfig>
Payment routes configuration

Exceptions / Errors

FacilitatorException
Base facilitator error
FacilitatorResponseException
Facilitator endpoint error (HTTP non-2xx)
InvalidPayloadException
Invalid payment payload
UnsupportedSchemeException
Unsupported scheme or network
X402Exception