FastAPI middleware for Coinbase x402 HTTP payment protocol on Base USDC
Project description
x402-solana
FastAPI middleware for the Coinbase x402 HTTP payment protocol on Base USDC.
Novel cross-chain primitive: bridges Solana wallet authentication with Coinbase x402 HTTP payments on Base — extracted from Sol Mate Trust API.
Install
pip install x402-solana
Usage
from fastapi import FastAPI, Depends
from x402_solana import require_x402_payment, X402Config, X402PaymentRequired, x402_exception_handler
app = FastAPI()
app.add_exception_handler(X402PaymentRequired, x402_exception_handler)
config = X402Config(
pay_to="0xYourBaseWalletAddress",
amount_usdc=0.5, # $0.50 USDC per request
description="DM unlock",
enabled=True, # Set False to bypass in dev
)
@app.post("/dm/send", dependencies=[Depends(require_x402_payment(config))])
async def send_dm(body: dict):
return {"status": "sent"}
Flow
Client → POST /dm/send (no X-Payment header)
Server → 402 Payment Required + {x402Version, accepts: [{network, asset, amount, payTo}]}
Client → pays 0.5 USDC on Base via Coinbase facilitator
Client → POST /dm/send (X-Payment: <proof>)
Server → verifies proof via https://x402.org/facilitator/verify
Server → 200 OK (request processed)
Configuration
| Field | Default | Description |
|---|---|---|
pay_to |
required | Base wallet address to receive USDC |
amount_usdc |
0.5 |
Payment amount in USDC |
network |
"base" |
"base" or "base-sepolia" |
asset |
USDC Base contract | ERC-20 token address |
description |
"API payment" |
Shown in wallet UI |
max_timeout_seconds |
300 |
Payment validity window |
enabled |
True |
Set False to bypass (dev/test) |
Graceful Degradation
If the Coinbase facilitator is unreachable, requests are allowed through automatically. Set enabled=False for local development.
License
MIT — extracted from Sol Mate Trust API. Built for EasyA × Consensus Miami 2026.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solmate_x402-0.1.0.tar.gz.
File metadata
- Download URL: solmate_x402-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1b69c6062fae89409fd5bba7ccb53504c60c3bba3e05f2811fc516173cbdea5
|
|
| MD5 |
7eadc7d540bbb0f29fe64556ad4ad8eb
|
|
| BLAKE2b-256 |
cbdd2a077935ba3f12a322108c64843a0d0af5daa02f94d62b621d22cc8f3a8a
|
File details
Details for the file solmate_x402-0.1.0-py3-none-any.whl.
File metadata
- Download URL: solmate_x402-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13474d933f2bf9719249bc1841aca0b2d555cea03f37b2983affa8d502f56711
|
|
| MD5 |
a0648fdc358e486fbb7af24ea7f9f7db
|
|
| BLAKE2b-256 |
c5ed047c0e13ea84dfc7be4c0c5e7daaeac0d01529b3ea2162815b7a6d8dd5bc
|