x402-guard with Coinbase AgentKit

Use this when an AgentKit action is about to pay an x402 seller. AgentKit already depends on @x402/fetch and @x402/evm. Attach the guard to that x402Client before wrapFetchWithPayment. This guide does not load a wallet key; use the signer you already get from the wallet provider (toSigner() or equivalent).

Install (until npm is live): curl -fsSL -o x402-guard.ts https://moneytools.dev/products/payment-safety/examples/x402-guard.ts
import { wrapFetchWithPayment, x402Client } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { attachToX402Client } from "./x402-guard.ts";

// signer: the one you already have from AgentKit's wallet provider (do not paste a key here).
export function payingFetch(signer: any, payer: string) {
  const client = new x402Client();
  registerExactEvmScheme(client, { signer });
  attachToX402Client(client, { payer, maxUsd: 0.05, dailyMaxUsd: 1, escalate: "high" });
  return wrapFetchWithPayment(fetch, client);
}

const paid = payingFetch(signer, "0xYourAgentWallet");
const res = await paid("https://seller.example/data");
console.log(res.status);

Put this paying fetch in any custom action provider that calls an x402 URL. Existing MoneyTools AgentKit actions can use the same pattern.

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/

All framework guides · Payment-safety suite · llms.txt