Machine Native Payments
x402 at the HTTP Layer
The Full Payment Pipeline
Example Handler
async function handle402(response, agentId) {
const header = response.headers['X-402-Payment'];
const requirement = JSON.parse(header);
const intent: PaymentIntent = {
agentId,
resourceUri: response.request.url,
amount: requirement.amount,
asset: requirement.asset,
merchant: requirement.merchant,
expiry: requirement.expiry,
nonce: requirement.nonce,
};
const approval = await policyEngine.evaluate(intent);
if (!approval.allowed) throw new Error('Payment not authorized');
const txHash = await accountAbstraction.pay(intent, approval);
await receiptIndexer.record(agentId, intent, txHash);
return retryRequestWithReceipt(response.request, txHash);
}Security Guarantees
Mechanism
Protection
Common Use Cases
Last updated
