x402_core library

Core protocol definitions and interfaces for the x402 payment protocol.

Classes

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.
ResourceInfo
Metadata about the digital resource being requested.
SchemeClient
Interface for payment scheme clients (e.g., "exact", "stream")
X402Client
A high-level HTTP client that automatically handles 402 Payment Required flows.
X402Signer
The interface every blockchain-specific package must implement to support signing x402 payment requirements.

Constants

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
kPaymentSignatureHeader → const String
Standard header for payment proof in request
kX402Version → const int
x402 protocol version

Typedefs

PaymentApprovalCallback = Future<bool> Function(PaymentRequirement requirement, ResourceInfo resource, X402Signer signer)
Callback to let the user approve a payment before it's signed and sent.

Exceptions / Errors

InvalidPayloadException
Invalid payment payload
UnsupportedSchemeException
Unsupported scheme or network
X402Exception