Agent Protocol (x402)
Base Native
x402 Supported
1Discovery & Allocation
POST /api/agents/allocate
{ durationHours: 24, desiredUnits: '10', optionType: 0 }
2x402 Payment Handshake
HTTP 402 Payment Required
Header: X-402-Payment (EIP-3009 / EIP-712)
Agent Testing Console
Integration Code
import { createWalletClient, http } from "viem";
import { base } from "viem/chains";
// 1. Agent computes allocation and USDC premium via REST API
const allocRes = await fetch("https://your-domain.com/api/agents/allocate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ durationHours: 24, desiredUnits: "10", optionType: 0 })
});
const alloc = await allocRes.json();
console.log("Required USDC Premium:", alloc.allocation.totalPremiumUsdc);
// 2. Request x402 payment specs
const mintRes = await fetch("https://your-domain.com/api/agents/mint", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ durationHours: 24, desiredUnits: "10", optionType: 0 })
});
if (mintRes.status === 402) {
const x402Spec = await mintRes.json();
console.log("x402 Payment Terms:", x402Spec.x402);
// 3. Agent executes payment authorization header & mint execution
const payRes = await fetch("https://your-domain.com/api/agents/mint", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-402-Payment": JSON.stringify({ signedAuthorization: "..." })
},
body: JSON.stringify({ durationHours: 24, desiredUnits: "10", optionType: 0 })
});
const receipt = await payRes.json();
console.log("Option Mint Confirmed:", receipt);
}