Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 1.81 KB

File metadata and controls

60 lines (40 loc) · 1.81 KB

x402 Client Examples

Example AI agents that consume x402-enabled financial APIs from Financial Oracles Gateway.

These examples show how to build agents that pay for data using the x402 protocol (USDC on Base).

Examples

1. Market Research Agent (market-agent.ts)

Fetches stock quotes, analyst ratings, and news using the /bundle/market_snapshot endpoint.

2. Sanctions Screening Agent (sanctions-agent.ts)

Screens names, addresses, and countries against OFAC lists using /bundle/sanctions_screen.

3. SEC Research Agent (sec-agent.ts)

Pulls company profiles, financials, insider trades, and events using /bundle/sec_snapshot.

Quick Start

# Install dependencies
bun install

# Set your wallet private key (for x402 payments)
export PRIVATE_KEY=0x...

# Run the free demo (no payment needed)
bun run demo.ts

# Run a paid example
bun run market-agent.ts AAPL

How x402 Works

  1. Request → Agent calls an endpoint (e.g., GET /stocks/quote/AAPL)
  2. 402 Response → Server returns pricing info and payment address
  3. Payment → Agent sends USDC on Base to the payment address
  4. Retry → Agent retries with X-Payment: <tx_hash> header
  5. Data → Server verifies payment and returns the data

The @x402/fetch SDK handles steps 2-4 automatically.

Dependencies

  • @x402/fetch — x402 payment-aware HTTP client
  • viem — Ethereum/Base wallet interactions

Gateway Info

  • Base URL: https://agents.krumpybot.com
  • Free demo: GET /demo/quote
  • Pricing: GET /pricing
  • Discovery: GET /.well-known/x402
  • Network: Base (Chain ID 8453)
  • Currency: USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)

License

MIT