Use this when an ElizaOS action is about to pay an x402 seller. Attach the guard to your existing official x402 client, then use the paying fetch inside the action. This guide does not load EVM_PRIVATE_KEY.
curl -fsSL -o x402-guard.ts https://moneytools.dev/products/payment-safety/examples/x402-guard.tsimport { wrapFetchWithPayment, x402Client } from "@x402/fetch";
import { attachToX402Client } from "./x402-guard.ts";
const client = new x402Client(); // register your existing scheme/signer
attachToX402Client(client, {
payer: "0xYourAgentWallet",
maxUsd: 0.05,
dailyMaxUsd: 1,
escalate: "high",
});
const paidFetch = wrapFetchWithPayment(fetch, client);
// Inside an ElizaOS action handler:
export async function fetchPaid({ url }: { url: string }) {
const res = await paidFetch(url);
return { text: `status ${res.status}
${await res.text()}` };
}
Character config and plugin registration stay as in your ElizaOS app. The guard only runs before a payment payload is created.
Install is free. Checks are billed per call at 0.005 USDC via x402 after the live free tier (Pay Precheck: 5/IP/endpoint/day; Settle: trial 50 calls / 7 days; Approval Relay: 3/day). The guard never loads a key, never signs, and never pays MoneyTools automatically. Docs: https://moneytools.dev/products/payment-safety/