// Dry run: call each paid endpoint WITHOUT a payment and parse the x402 v2 402 challenge.
// No wallet, no key, no money moves. Usage: npm run dry-run [-- webread]
import { decodePaymentRequiredHeader } from '@x402/core/http';
import { TOOLS, type ToolKey } from './tools.js';
const only = process.argv[2] as ToolKey | undefined;
let failed = 0;
for (const [key, t] of Object.entries(TOOLS)) {
if (only && key !== only) continue;
const res = await fetch(t.url);
const header = res.headers.get('PAYMENT-REQUIRED');
if (res.status !== 402 || !header) { console.log(`${t.name}: expected 402 + PAYMENT-REQUIRED, got ${res.status}`); failed++; continue; }
const pr = decodePaymentRequiredHeader(header);
const a = pr.accepts[0];
console.log(`${t.name}: 402 OK, x402 v${pr.x402Version}, ${Number(a.amount) / 1e6} USDC (${a.amount} atomic) on ${a.network} to ${a.payTo}, resource ${pr.resource?.url}, listed as "${(pr.resource as any)?.serviceName}"`);
}
process.exit(failed ? 1 : 0);
agentgate-source: code mirror on Cloudflare Pages. All repos