Skip to main content
This guide walks through building a client that can automatically pay for x402-protected resources on Abstract.
  • A wallet with USDC on Abstract mainnet or testnet
  • Node.js 18+, Go 1.21+, or Python 3.10+

1. Install the client SDK

npm install @x402/fetch @x402/core @x402/evm viem

2. Create a signer

import { privateKeyToAccount } from "viem/accounts";

const signer = privateKeyToAccount(
  process.env.PRIVATE_KEY as `0x${string}`
);

3. Wrap your HTTP client

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const signer = privateKeyToAccount(
  process.env.PRIVATE_KEY as `0x${string}`
);

const client = new x402Client();
client.register("eip155:*", new ExactEvmScheme(signer));

const fetchWithPayment = wrapFetchWithPayment(fetch, client);

const response = await fetchWithPayment(
  "https://api.example.com/weather",
  { method: "GET" },
);

const data = await response.json();
console.log(data);

4. Agent runtime notes

For an automated agent:
  • keep the signer scoped to the smallest viable balance
  • separate read-only and paid-request workflows
  • log payment receipts so you can reconcile usage later

Next

  • Continue to AGW CLI if the agent should use AGW instead of a raw private key
  • Compare with MPP if your client will make repeated paid requests