02 / SOURCE
Let the 402 response set the terms.
The source uses Node's built-in fetch. It reads the challenge and returns the terms. It imports no wallet, key, or payment library.
voidly-brief-terms.mjsJAVASCRIPT
// voidly-brief-terms.mjs — Node.js 20+; reads unpaid 402 terms, never pays
import { pathToFileURL } from 'node:url';
const RESOURCE = 'https://x402.voidly.ai/v1/services/svc_e756b894c55a4026aa66dca4ca293ff5/call';
export async function briefTerms(country = 'IR') {
const code = String(country).trim();
if (!/^[A-Za-z]{2}$/.test(code)) throw new Error('Country must be two letters');
const response = await globalThis.fetch(RESOURCE, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ country: code }),
});
if (response.status !== 402) throw new Error('Expected an unpaid 402, got HTTP ' + response.status);
const encoded = response.headers.get('payment-required');
if (!encoded) throw new Error('Missing PAYMENT-REQUIRED header');
const challenge = JSON.parse(Buffer.from(encoded, 'base64').toString('utf8'));
if (!Array.isArray(challenge.accepts)) throw new Error('Missing payment terms');
return challenge.accepts.map(({ scheme, network, asset, amount, payTo, maxTimeoutSeconds }) => (
{ scheme, network, asset, amount, payTo, maxTimeoutSeconds }
));
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
console.log(JSON.stringify(await briefTerms(process.argv[2] ?? 'IR'), null, 2)); // Unpaid 402 only.
}