Documentation
¶
Overview ¶
Package x402 implements the X402 HTTP payment protocol for blockchain micropayments. It uses the Coinbase X402 V2 Go SDK for automatic payment handling when agents encounter HTTP 402 responses from X402-enabled services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CAIP2Network ¶
CAIP2Network converts a numeric chain ID to a CAIP-2 network identifier. Example: 84532 -> "eip155:84532"
func NewX402Client ¶
func NewX402Client(signerProvider SignerProvider, chainID int64) (*x402sdk.X402Client, error)
NewX402Client creates an X402 SDK client configured for the given chain and signer. The client is registered with the exact EVM scheme for the specified CAIP-2 network.
Types ¶
type Config ¶
type Config struct {
// Enabled controls whether X402 automatic payment is active.
Enabled bool
// ChainID is the numeric EVM chain ID (e.g. 84532 for Base Sepolia).
ChainID int64
// MaxAutoPayAmount is the maximum USDC amount for automatic payments (e.g. "1.00").
MaxAutoPayAmount string
}
Config holds X402 interceptor configuration.
type Interceptor ¶
type Interceptor struct {
// contains filtered or unexported fields
}
Interceptor provides an X402-enabled HTTP client via the Coinbase SDK. It lazily initializes the wrapped client and enforces spending limits through the SDK's BeforePaymentCreation hook.
func NewInterceptor ¶
func NewInterceptor(sp SignerProvider, limiter wallet.SpendingLimiter, cfg Config, logger *zap.SugaredLogger) *Interceptor
NewInterceptor creates an X402 interceptor.
func (*Interceptor) HTTPClient ¶
HTTPClient returns an *http.Client that automatically handles HTTP 402 responses using the X402 V2 protocol. The client is created lazily and cached.
func (*Interceptor) IsEnabled ¶
func (i *Interceptor) IsEnabled() bool
IsEnabled returns whether the interceptor is active.
func (*Interceptor) SignerAddress ¶
func (i *Interceptor) SignerAddress(ctx context.Context) (string, error)
SignerAddress returns the wallet address of the configured signer.
type LocalSignerProvider ¶
type LocalSignerProvider struct {
// contains filtered or unexported fields
}
LocalSignerProvider loads the private key from SecretsStore and creates an SDK signer.
func NewLocalSignerProvider ¶
func NewLocalSignerProvider(secrets *security.SecretsStore) *LocalSignerProvider
NewLocalSignerProvider creates a signer provider backed by the local secrets store.
func (*LocalSignerProvider) EvmSigner ¶
func (p *LocalSignerProvider) EvmSigner(ctx context.Context) (evm.ClientEvmSigner, error)
EvmSigner loads the private key, creates an SDK ClientEvmSigner, then zeros the key material.
type SignerProvider ¶
type SignerProvider interface {
EvmSigner(ctx context.Context) (evm.ClientEvmSigner, error)
}
SignerProvider creates an EVM signer for X402 payments.