forked from https://github.com/coinbase/x402/tree/main/go
x402-go is an early-stage Go project in the AI payments / x402 ecosystem. It currently has 0 GitHub stars and 0 forks.
Go implementation of the x402 protocol - a standard for HTTP 402 Payment Required responses with cryptocurrency micropayments.
x402 is a protocol that enables HTTP resources to require cryptocurrency payments. When a client requests a paid resource, the server responds with 402 Payment Required along with payment details. The client creates a payment, retries the request, and receives the resource after successful payment verification and settlement.
go get x402-go
This repository contains a subset of the x402 repository. To pull the latest changes from upstream while preserving your local modifications:
./sync_upstream.sh
This script will:
upstream remote if neededgo directory from upstream into your current branch using git subtree logicThis package provides modules to support the x402 protocol in Go applications.
The package exports three core types that can be used by clients, servers, and facilitators:
x402.X402Client - Creates payment payloads for clients making paid requestsx402.X402ResourceServer - Verifies payments and builds requirements for servers accepting paymentsx402.X402Facilitator - Verifies and settles payments for facilitator servicesThese core classes are framework-agnostic and can be used in any context (HTTP, gRPC, WebSockets, CLI tools, etc.).
The package exports HTTP-specific wrappers around the core classes:
x402http.HTTPClient - Wraps http.Client with automatic payment handling for clientsx402http.HTTPServer - Integrates resource server with HTTP request processingx402http.HTTPFacilitatorClient - HTTP client for calling facilitator endpointsThese wrappers handle HTTP-specific concerns like headers, status codes, and request/response serialization.
Framework-specific middleware packages for easy server integration:
http/gin - Gin framework middlewareAdditional framework middleware can be built using the HTTP transport wrappers as a foundation.
Helper packages to simplify client implementation:
signers/evm - EVM signer helpers (creates signers from private keys)signers/svm - SVM signer helpers (creates signers from private keys)These eliminate 95-99% of boilerplate code for creating signers.
Payment scheme implementations that can be registered by clients, servers, and facilitators:
mechanisms/evm/exact - Ethereum/Base exact payment using EIP-3009
client/ - Client-side payment creationserver/ - Server-side payment verificationfacilitator/ - Facilitator-side payment settlementmechanisms/svm/exact - Solana exact payment using token transfers
client/ - Client-side payment creationserver/ - Server-side payment verificationfacilitator/ - Facilitator-side payment settlementEach role (client, server, facilitator) has its own mechanism implementation with appropriate functionality for that role.
Protocol extension implementations:
extensions/bazaar - API discovery extension for making resources discoverableThe package is designed with extreme modularity:
┌─────────────────────────────────────────┐
│ Your Application │
└─────────────────────────────────────────┘
│
┌──────────┼──────────┐
▼ ▼ ▼
[Client] [Server] [Facilitator]
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────┐
│ HTTP Layer (Optional) │
│ - HTTPClient wrapper │
│ - HTTPResourceServer │
│ - Middleware (Gin, etc.) │
└─────────────────────────────────────────┘
│
┌──────────┼──────────┐
▼ ▼ ▼
┌─────────────────────────────────────────┐
│ Core Classes (Framework-Agnostic) │
│ - X402Client │
│ - X402ResourceServer │
│ - X402Facilitator │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ Mechanisms (Pluggable) │
│ - EVM exact (client/server/facil.) │
│ - SVM exact (client/server/facil.) │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ Signers (Helpers) │
│ - EVM client signers │
│ - SVM client signers │
└─────────────────────────────────────────┘
Framework-Agnostic Core - The core client/server/facilitator classes work independently of HTTP or any web framework
HTTP as a Layer - HTTP functionality is isolated in the http package, making the core reusable for other transports
Pluggable Mechanisms - Payment schemes are modular and can be registered independently by clients, servers, and facilitators
Middleware Wraps Core - Framework middleware (like Gin) internally uses the core primitives, keeping framework concerns separate
This architecture enables:
This package serves three distinct roles. Choose the documentation for what you're building:
For applications that make requests to payment-protected resources.
Topics covered:
See also: examples/go/clients/
For services that protect resources with payment requirements.
Topics covered:
See also: examples/go/servers/
For payment processing services that verify and settle payments.
Topics covered:
See also: examples/go/facilitator/, e2e/facilitators/go/
x402-go
│
├── Core (framework-agnostic)
│ ├── client.go - x402.X402Client
│ ├── server.go - x402.X402ResourceServer
│ ├── facilitator.go - x402.X402Facilitator
│ ├── types.go - Core types
│ └── *_hooks.go - Lifecycle hooks
│
├── http/ - HTTP transport layer
│ ├── http.go - Type aliases and convenience functions
│ ├── client.go - HTTP client wrapper
│ ├── server.go - HTTP server integration
│ ├── facilitator_client.go - Facilitator HTTP client
│ └── gin/ - Gin middleware
│
├── mechanisms/ - Payment schemes
│ ├── evm/exact/
│ │ ├── client/ - EVM client mechanism
│ │ ├── server/ - EVM server mechanism
│ │ └── facilitator/ - EVM facilitator mechanism
│ └── svm/exact/
│ ├── client/ - SVM client mechanism
│ ├── server/ - SVM server mechanism
│ └── facilitator/ - SVM facilitator mechanism
│
├── signers/ - Signer helpers
│ ├── evm/ - EVM client signers
│ └── svm/ - SVM client signers
│
├── extensions/ - Protocol extensions
│ └── bazaar/ - API discovery
│
└── types/ - Type definitions
├── v1.go - V1 protocol types
├── v2.go - V2 protocol types
├── helpers.go - Version detection utilities
├── raw.go - Raw type handling
└── extensions.go - Extension type definitions
All EVM-compatible chains using CAIP-2 identifiers:
eip155:1)eip155:8453)eip155:84532)Use eip155:* wildcard to support all EVM chains.
All Solana networks using CAIP-2 identifiers:
solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp)solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1)solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z)Use solana:* wildcard to support all Solana networks.
Transfer an exact amount to access a resource:
transferWithAuthorization (USDC compatible tokens)# Run all tests
go test ./...
# Run with coverage
go test -cover ./...
# Run integration tests
go test ./test/integration/...
See CONTRIBUTING.md for contribution guidelines.
Apache 2.0 - See LICENSE for details.
Your AI trading terminal assistant for US stocks, commodities, forex, and crypto.
Golang SDK for A2A Protocol
Publishes localhost services to the agentic web through self-hostable, trustless relays with x402 payments.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Go implementation of the x402 payment protocol