A prototype for a machine-to-machine "paid verification" flow using HTTP 402 (Payment Required) as specified in the agent-org bounty.
- Request: Client requests a protected resource (e.g.,
GET /resource). - Challenge: Server responds with HTTP 402 Payment Required and a JSON body containing:
- Payment instructions (Amount, Asset, Destination Address, Chain).
- A unique
referenceID (nonce).
- Payment: Client sends the required amount (e.g., 1.0 USDC on Base) with the reference ID (as a memo or in the transaction).
- Verification: Client retries the request or calls
/verifywith thetxHashandreference. - Access: Once verified on-chain (Base Mainnet), the server grants access to the resource.
- Node.js (v18+)
npm install
node index.jsbash demo.sh{
"error": "Payment Required",
"instructions": {
"message": "To access this resource, send 1.0 USDC on Base network.",
"destination": "0x679D879F5d71e165bEcF5fEF4AEB595e82c055E0",
"amount": "1.0",
"asset": "USDC",
"chain": "Base",
"reference": "unique-nonce-here",
"expiry": "30 minutes"
}
}Endpoint: POST /verify
Body:
{
"reference": "unique-nonce-here",
"txHash": "0x..."
}- Express: HTTP Server
- Ethers.js: On-chain verification (Base Mainnet)
- Dotenv: Environment management