Skip to content

dpx-x402 — x402 Payment Middleware

@untitledfinancial/dpx-x402 is a server middleware package that gates any API endpoint behind x402 USDC micropayments on Base mainnet. The caller is always an autonomous agent — no human approves the payment, no human is in the loop.

Terminal window
npm install @untitledfinancial/dpx-x402

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 and retries. Your server verifies the signature on-chain and responds. The entire loop is machine-to-machine.

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)
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 app
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 })
)
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 })
})

Compatible with any Fetch API-based framework — Deno, Bun, or any custom handler.

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)
}
DPX.create({
// Required
recipient: '0x...', // Address that receives USDC payments
secretKey: process.env.SECRET!, // For signing receipts — keep server-side, never log
// Optional
currency: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base (default)
network: 'base', // 'base' (default) or 'base-sepolia' for testnet
waitForConfirmation: true, // Wait for on-chain confirmation (default: true)
// Set false for optimistic low-latency responses
})

Amount, currency, and recipient can be overridden per route — useful for tiered pricing or per-product wallets:

dpx.charge({
amount: '0.75', // Different price for a more expensive signal
currency: '0x...', // EURC for EUR-denominated routes
recipient: '0x...', // Per-product wallet
})

Every verified response includes an X-Payment-Response header with a receipt:

{
"paid": true,
"from": "0x<agent-wallet>",
"to": "0x<your-wallet>",
"amount": "0.15",
"currency": "0x833589...",
"network": "eip155:8453",
"verifiedAt": "2026-07-25T14:00:00Z"
}

Set network: 'base-sepolia' and fund your agent wallet with testnet USDC from the Circle faucet.

dpx-x402 verifies payments without a mandatory RPC call:

  1. Parses the X-Payment header (JSON)
  2. Recovers the signer from the EIP-712 signature using viem
  3. Confirms signer matches from, to matches recipient, value ≥ required amount, and timing is valid
  4. Optionally checks USDC balance on-chain (configurable)

Signature verification is cryptographic and requires no network call — suitable for Cloudflare Workers edge deployments.

dpx-x402 accepts USDC on Base mainnet via EIP-3009 TransferWithAuthorization by default. Any agent with a funded Base wallet can pay — no new token, no onboarding required.

For EUR-denominated routes, override currency with the EURC contract address on Base.

If you are building the agent that calls an dpx-x402-gated endpoint, see:

Terminal window
npm install @untitledfinancial/dpx-x402

View on npm →