Agent onboarding

Copy, pay, execute, verify.

These examples give agents a short path from discovery to a paid x402 call and a verifiable receipt. Use the exact route metadata from capabilities or Bazaar when building a production client.

AgentCash

One paid execution from PowerShell.

This is the fastest buyer smoke test. The --% marker keeps Windows PowerShell from rewriting the JSON body.

npx --% agentcash fetch https://action402.vercel.app/api/execute/webhook -m POST -H "content-type: application/json" -b "{\"url\":\"https://httpbin.org/anything\",\"method\":\"POST\",\"headers\":{\"content-type\":\"application/json\"},\"body\":{\"event\":\"agent.onboarding\",\"message\":\"hello from an x402 buyer\"},\"idempotencyKey\":\"agent-onboarding-001\",\"retry\":{\"attempts\":2,\"backoffMs\":300},\"timeoutMs\":10000}" --payment-protocol x402 --payment-network base --max-amount 0.01 -y --format json

CDP Agentic Wallet

Discover Action402 before paying.

CDP Agentic Wallet CLI can search Bazaar without wallet balance, then inspect the endpoint's payment requirements before the agent makes a paid request.

npx awal@latest x402 bazaar search "Action402" -k 5 --json
npx awal@latest x402 details https://action402.vercel.app/api/execute/webhook --json

CDP wallet app

Use fetchWithX402 when your runtime has a CDP wallet.

CDP documents fetchWithX402 as the vanilla JavaScript path for wallet-backed x402 payments. The wrapped fetch handles the 402 challenge and retries with payment proof.

import { fetchWithX402 } from "@coinbase/cdp-core";

const wrappedFetch = fetchWithX402();
const response = await wrappedFetch("https://action402.vercel.app/api/execute/webhook", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    url: "https://httpbin.org/anything",
    method: "POST",
    body: { event: "agent.cdp-wallet" },
    idempotencyKey: "cdp-wallet-action-001",
    timeoutMs: 10000
  })
});

const result = await response.json();
const verify = await fetch(`https://action402.vercel.app/api/verify/jobs/${result.job.id}`);
console.log(await verify.json());

Generic x402 client

Lower-level buyer flow for code-based agents.

Provide an EVM signer from the agent wallet you control. CDP wallets can be used here when your runtime exposes a viem-compatible signer or account abstraction.

import { x402Client } from "@x402/core/client";
import { x402HTTPClient } from "@x402/core/http";
import { ExactEvmScheme } from "@x402/evm/exact/client";

const coreClient = new x402Client()
  .register("eip155:*", new ExactEvmScheme(evmSigner));

const client = new x402HTTPClient(coreClient);
const body = {
  url: "https://httpbin.org/anything",
  method: "POST",
  body: { event: "agent.onboarding" },
  idempotencyKey: "agent-onboarding-001",
  timeoutMs: 10000
};

const unpaid = await fetch("https://action402.vercel.app/api/execute/webhook", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify(body)
});

if (unpaid.status !== 402) throw new Error(`expected 402, got ${unpaid.status}`);

const paymentRequired = client.getPaymentRequiredResponse(
  (name) => unpaid.headers.get(name),
  await unpaid.json()
);
const paymentPayload = await client.createPaymentPayload(paymentRequired);
const paid = await fetch("https://action402.vercel.app/api/execute/webhook", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    ...client.encodePaymentSignatureHeader(paymentPayload)
  },
  body: JSON.stringify(body)
});

const result = await paid.json();
const verify = await fetch(`https://action402.vercel.app/api/verify/jobs/${result.job.id}`);
console.log(await verify.json());

Production checklist

What an agent should do every time.

The contract is intentionally small, so buyer logic can be strict. Discover, cap spend, pass an idempotency key, and verify the receipt before marking the action complete.

1

Read price and limits

Use /api/capabilities or Bazaar metadata instead of hard-coding.

2

Set max payment

Reject unexpected price changes with a buyer-side max amount guardrail.

3

Use idempotency

Send a stable idempotencyKey for retries and agent restarts.

4

Verify proof

Call /api/verify/jobs/{id} or /api/verify/receipts/{id}.