@untitledfinancial/dpx-x402
v1.0.1
Published
x402 payment middleware for any server framework — gate your API endpoints behind USDC micropayments on Base mainnet
Maintainers
Readme
@untitledfinancial/dpx-x402
Gate any API endpoint behind USDC micropayments on Base mainnet. Agents pay automatically — no account, no API key, no subscription.
npm install @untitledfinancial/dpx-x402How it works
An agent calls your endpoint. If no payment is attached, your server returns a 402 Payment Required with USDC payment details. The agent signs an EIP-3009 transfer from its funded wallet, retries with the X-Payment header, and your server verifies and responds. The entire loop is machine-to-machine — no human approves anything.
Agent → GET /your-endpoint
Server → 402: { amount: "150000", asset: USDC, payTo: "0x..." }
Agent signs EIP-3009 TransferWithAuthorization
Agent → GET /your-endpoint (X-Payment: <signed token>)
Server verifies → 200: { your data } (X-Payment-Response: receipt)Cloudflare Workers / Hono
import { Hono } from 'hono'
import { DPX } from '@untitledfinancial/dpx-x402/hono'
const app = new Hono()
const dpx = DPX.create({
recipient: '0xYourWalletAddress',
secretKey: process.env.DPX_SECRET_KEY!,
})
// Gate a route — $0.15 USDC per call
app.get('/signal', dpx.hono.charge({ amount: '0.15' }), (c) =>
c.json({ regime: 'STABLE', score: 42 })
)
export default appNext.js App Router
// app/api/signal/route.ts
import { DPX } from '@untitledfinancial/dpx-x402/nextjs'
const dpx = DPX.create({
recipient: '0xYourWalletAddress',
secretKey: process.env.DPX_SECRET_KEY!,
})
export const GET = dpx.charge({ amount: '0.15' })(() =>
Response.json({ regime: 'STABLE', score: 42 })
)Express / Node.js
import express from 'express'
import { DPX } from '@untitledfinancial/dpx-x402/express'
const app = express()
const dpx = DPX.create({
recipient: '0xYourWalletAddress',
secretKey: process.env.DPX_SECRET_KEY!,
})
app.get('/signal', dpx.node.charge({ amount: '0.15' }), (req, res) => {
res.json({ regime: 'STABLE', score: 42 })
})Manual mode (raw Fetch API)
import { DPX } from '@untitledfinancial/dpx-x402'
const dpx = DPX.create({
recipient: '0xYourWalletAddress',
secretKey: process.env.DPX_SECRET_KEY!,
})
export async function handler(request: Request): Promise<Response> {
return dpx.charge({ amount: '0.15' })(
() => Response.json({ regime: 'STABLE', score: 42 })
)(request)
}Configuration
DPX.create({
// Required
recipient: '0x...', // Address that receives USDC payments
secretKey: process.env.SECRET!, // Secret for signing receipts — never expose
// Optional
currency: '0x833589...', // USDC on Base (default). Override for EURC or other tokens.
network: 'base', // 'base' (default) or 'base-sepolia' for testnet
waitForConfirmation: true, // Wait for on-chain confirmation (default: true)
// Set false for lower latency (optimistic)
})Per-route overrides
// Different amount, currency, or recipient per route
dpx.charge({
amount: '0.75',
currency: '0x...', // e.g. EURC for EUR-denominated routes
recipient: '0x...', // e.g. per-product wallet
})Payment methods
By default, dpx-x402 accepts USDC on Base mainnet via EIP-3009 TransferWithAuthorization. This is the same mechanism used by DPX Intelligence and all x402-gated DPX endpoints.
Any agent with a funded Base wallet can pay immediately — no new token, no onboarding.
Testnet
Set network: 'base-sepolia' and fund your agent wallet with testnet USDC from the Circle faucet.
What the agent receives
Every verified response includes an X-Payment-Response header:
{
"paid": true,
"from": "0x<agent-wallet>",
"to": "0x<your-wallet>",
"amount": "0.15",
"currency": "0x833589...",
"network": "eip155:8453",
"verifiedAt": "2026-07-25T14:00:00Z"
}Agent-side: paying with dpx-x402
If you are building the agent side (the caller), see:
- DPX Intelligence docs — example x402 signing code in Python
- x402 protocol reference — full EIP-3009 flow
Discovery
After your server is running, add a GET /openapi.json endpoint so agents can discover your API and its payment terms. Tag paid routes with x-payment-info:
{
"paths": {
"/signal": {
"get": {
"x-payment-info": {
"offers": [{ "amount": "0.15", "currency": "USDC", "network": "base" }]
}
}
}
}
}License
Business Source License 1.1 — see LICENSE.
