x402-payment-link is an established HTML project in the AI payments / x402 ecosystem. It currently has 201 GitHub stars and 3 forks.
A Flask-based payment page demo implementing the x402 protocol for USDC cryptocurrency payments on the Base chain. Uses the Coinbase facilitator for payment verification and settlement.
# Clone the repository
git clone <repository-url>
cd x402-payment-link
# Install dependencies
uv sync
# Copy environment template and configure
cp .env.example .env
# Edit .env with your wallet address
python3 main.py
The server starts at http://localhost:5000 (or your configured APP_PORT).
docker compose up --build
http://localhost:5000/demo in your browserCreate a .env file in the project root. See .env.example for a template.
| Variable | Description | Example |
|---|---|---|
ADDRESS |
Wallet address for receiving USDC payments | 0xYourBaseWalletAddress |
NETWORK |
Blockchain network | base-sepolia (testnet) or base (mainnet) |
| Variable | Default | Description |
|---|---|---|
APP_PORT |
5000 |
Server port |
ENVIRONMENT |
staging |
Affects product pricing (staging or production) |
MAX_DEADLINE_SECONDS |
60 |
Payment timeout in seconds |
FACILITATOR_URL |
https://x402f1.secondstate.io |
x402 facilitator service URL |
APP_NAME |
x402-mvp |
Application name shown in paywall |
APP_LOGO |
/static/secondstate.png |
Logo URL for paywall |
To send order confirmation emails via SendGrid:
| Variable | Description |
|---|---|
SENDGRID_API_KEY |
Your SendGrid API key |
FROM_EMAIL |
Sender email address |
ORDER_CONFIRMATION_RECIPIENT |
CC recipient for order confirmations |
The x402 protocol enables HTTP-native cryptocurrency payments using the 402 Payment Required status code.
┌──────────┐ ┌──────────────┐ ┌─────────────┐ ┌─────────────┐
│ Browse │────▶│ Submit Order │────▶│ Payment 402 │────▶│ Settlement │
│ Product │ │ Form │ │ Requirements│ │ Confirmation│
└──────────┘ └──────────────┘ └─────────────┘ └─────────────┘
GET /<product>) - User views product page with pricingPOST /<product>/order) - Order details saved, redirects to paymentGET /<product>/order/<order_id>) - Returns 402 with payment requirements if no X-PAYMENT headerX-PAYMENT header; facilitator verifies and settles on blockchain├── main.py # Flask application entry point
├── config.py # Environment configuration
├── products.yaml # Product catalog
├── services/
│ ├── product_service.py # Product catalog management
│ ├── order_service.py # Order persistence (JSONL)
│ ├── payment_service.py # x402 payment verification/settlement
│ └── notification_service.py # SendGrid email notifications
├── templates/
│ └── <product_id>/
│ ├── product.html # Product landing page
│ ├── order_confirmation.html # Success page
│ └── order_confirmation_email.html # Email template
├── static/ # Static assets (images, etc.)
├── data/ # Runtime data (orders, logs)
├── Dockerfile
└── docker-compose.yaml
products.yaml:my_product:
name: My Product
description: "Product description here"
image: https://example.com/image.png
staging:
price: 0.10
shipping: 0.00
production:
price: 29.99
shipping: 4.99
templates/my_product/:product.html - Product landing page with order formorder_confirmation.html - Post-payment success pageorder_confirmation_email.html - Email template (optional)The docker-compose.yaml configuration:
services:
x402-mvp:
build: .
restart: unless-stopped
ports:
- "${SERVER_PORT}:${APP_PORT}"
volumes:
- ./.env:/app/.env
- ./data:/app/data
Volume Mounts:
.env - Configuration filedata/ - Persistent storage for orders (<product>.txt) and logs (app.log)Port Configuration:
SERVER_PORT in your environment for the external portAPP_PORT in .env for the internal Flask port| Service | Purpose |
|---|---|
product_service |
Reads product catalog from products.yaml |
order_service |
Generates order IDs, stores orders as JSONL in data/ |
payment_service |
Creates payment requirements, verifies/settles via facilitator |
notification_service |
Sends confirmation emails via SendGrid |
NETWORK=base-sepolia in .envENVIRONMENT=staging for lower test prices ($0.10)Orders are stored as JSON lines in data/<product>.txt:
{"time":"2024-01-01T12:00:00","email":"user@example.com","order_id":"ABC123","quantity":1,"total":"0.10","payment":false}
After payment settlement, a new entry is appended with "payment":true.
See LICENSE for details.
Your AI trading terminal assistant for US stocks, commodities, forex, and crypto.
The agent-native LLM router for autonomous agents. 55+ models (8 free), <1ms local routing, USDC payments on Base & Solana via x402.
A payments protocol for the internet. Built on HTTP.
A local-first AI agent with persistent memory, emotional intelligence, and a peer-to-peer skills economy.
The trust layer for agent-to-agent commerce — natural-language mandates, ERC-7710 delegated permissions, x402 payments, escrow, and dispute resolution as one open, catch-all Agent Skill / Claude Code plugin.
The AI agent with a wallet — spends USDC autonomously to get real work done. Apache-2.0, TypeScript.