go-x402-facilitator is a facilitator for X402 payment implemented in the Go language.
go-x402-facilitator is an early-stage Go project in the AI payments / x402 ecosystem. It currently has 8 GitHub stars and 0 forks.
X402 payment facilitator service written in Go, supporting exact@EVM payment scheme verification and settlement.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ HTTP API │ │ Facilitator │ │ EVM Clients │
│ (Gin) │───▶│ Service │───▶│ (go-ethereum) │
│ │ │ │ │ │
│ /verify │ │ - Verify logic │ │ - RPC calls │
│ /settle │ │ - Settle logic │ │ - Transaction │
│ /supported │ │ - Network info │ │ execution │
│ /health │ │ - EIP-712 sig │ │ - Balance check │
│ /ready │ │ verification │ │ - Nonce check │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Install dependencies:
go mod download
Configure:
cp env.example .env
# Edit .env file with your configuration
# Required: FACILITATOR_PRIVATE_KEY
# Required: FACILITATOR_CHAIN_RPC
# Required: FACILITATOR_CHAIN_ID
# Required: FACILITATOR_TOKEN_ADDRESS
Run:
# Using .env file (automatically loaded)
go run cmd/main.go
# Or specify custom config file
go run cmd/main.go -config .env
# Or use start script
./start.sh
POST /facilitator/verify
Content-Type: application/json
{
"paymentPayload": {
"x402Version": 1,
"scheme": "exact",
"network": "localhost",
"payload": {
"signature": "0x...",
"authorization": {
"from": "0x...",
"to": "0x...",
"value": "10000",
"validAfter": "1740672089",
"validBefore": "1740672154",
"nonce": "0x..."
}
}
},
"paymentRequirements": {
"scheme": "exact",
"network": "localhost",
"maxAmountRequired": "10000",
"resource": "https://api.example.com/premium-data",
"description": "Access to premium market data",
"payTo": "0x209693Bc6afc0C5328bA36FaF03C514EF312287C",
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
}
}
Note: The network field must match the FACILITATOR_NETWORK configuration value.
Response:
{
"isValid": true,
"invalidReason": "",
"payer": "0x857b06519E91e3A54538791bDbb0E22373e36b66"
}
POST /facilitator/settle
Content-Type: application/json
# Same request body as /verify endpoint
Response:
{
"success": true,
"errorReason": "",
"transaction": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"network": "localhost",
"payer": "0x857b06519E91e3A54538791bDbb0E22373e36b66"
}
GET /facilitator/supported
Response:
{
"x402Version": 1,
"kinds": [
{
"x402Version": 1,
"scheme": "exact",
"network": "localhost"
}
]
}
GET /health - Basic health statusGET /ready - Detailed readiness status (checks if facilitator is initialized)The service is configured via environment variables. You can use a .env file (see env.example) or set environment variables directly.
| Variable | Description | Default |
|---|---|---|
SERVER_HOST |
Server host address | 0.0.0.0 |
SERVER_PORT |
Server port | 8080 |
SERVER_READ_TIMEOUT |
Read timeout duration | 30s |
SERVER_WRITE_TIMEOUT |
Write timeout duration | 30s |
SERVER_IDLE_TIMEOUT |
Idle timeout duration | 120s |
SERVER_LOG_LEVEL |
Log level (trace, debug, info, warn, error, fatal, panic) | info |
SERVER_LOG_FORMAT |
Log format (json, console) | json |
| Variable | Description | Default | Required |
|---|---|---|---|
FACILITATOR_NETWORK |
Network identifier (e.g., localhost, base-sepolia) | localhost |
Yes |
FACILITATOR_CHAIN_RPC |
Ethereum RPC endpoint URL | http://127.0.0.1:8545 |
Yes |
FACILITATOR_CHAIN_ID |
Chain ID for the network | 1337 |
Yes |
FACILITATOR_TOKEN_ADDRESS |
ERC20 token contract address | - | Yes |
FACILITATOR_TOKEN_NAME |
Token name (for EIP-712) | MyToken |
No |
FACILITATOR_TOKEN_VERSION |
Token version (for EIP-712) | 1 |
No |
FACILITATOR_TOKEN_DECIMALS |
Token decimals | 6 |
No |
FACILITATOR_PRIVATE_KEY |
Private key for transaction signing (hex format, no 0x prefix) | - | Yes |
FACILITATOR_GAS_LIMIT |
Gas limit for transactions | 100000 |
No |
FACILITATOR_GAS_PRICE |
Gas price (leave empty for auto) | - | No |
FACILITATOR_SUPPORTED_SCHEME |
Supported payment scheme | exact |
No |
# Server Configuration
SERVER_HOST=0.0.0.0
SERVER_PORT=8080
SERVER_READ_TIMEOUT=30s
SERVER_WRITE_TIMEOUT=30s
SERVER_IDLE_TIMEOUT=120s
SERVER_LOG_LEVEL=info
SERVER_LOG_FORMAT=json
# Facilitator Configuration
FACILITATOR_NETWORK=localhost
FACILITATOR_CHAIN_RPC=http://127.0.0.1:8545
FACILITATOR_CHAIN_ID=1337
FACILITATOR_TOKEN_ADDRESS=0xYourTokenAddress
FACILITATOR_TOKEN_NAME=MyToken
FACILITATOR_TOKEN_VERSION=1
FACILITATOR_TOKEN_DECIMALS=6
FACILITATOR_PRIVATE_KEY=your-private-key-hex-without-0x-prefix
FACILITATOR_GAS_LIMIT=100000
FACILITATOR_SUPPORTED_SCHEME=exact
The service uses structured JSON logging (or console format) with the following features:
X-Request-ID header)Log fields include:
service - Service name ("x402-facilitator")version - Service version (1.0.0)request_id - Unique request identifiermethod - HTTP methodpath - Request pathstatus - HTTP status codeduration_ms - Request duration in milliseconds.env file should be in .gitignore# Build binary
go build -o x402-facilitator ./cmd/main.go
# Or using the standard Go build command
go build -o bin/x402-facilitator ./cmd
See the examples/ directory for example usage:
cd examples
# Set up environment variables (see examples/common.go)
go run pay.go
This project is licensed under the Apache License - see the LICENSE file 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