DEV Community

Nathaniel Cruz
Nathaniel Cruz

Posted on

How Cursor Background Agents Can Buy Live DeFi Yields, Token Alerts, and Market Data with x402

Cursor is quietly becoming more than an IDE. With background agents that run autonomously in the background, it's turning into a platform where code can buy things on its own — data feeds, skill protocols, intelligence endpoints — without a human in the loop.

The payment layer that makes this work is x402. If you haven't heard of it: x402 is an HTTP protocol standard (now backed by Cloudflare and Coinbase's x402 Foundation) where a server responds to an unauthorized request with HTTP 402 Payment Required — and the response body tells the agent exactly what to pay, to whom, and how. The agent pays with USDC on Base, includes a signed payment proof in an X-Payment header, and gets the data.

This post walks through how Cursor agents use x402 to buy live DeFi yields, token anomaly alerts, and market data. Code included.


1. The 402 Response: What Cursor Agents See First

When a Cursor background agent hits a data endpoint without payment, it gets a 402. Here's what that looks like from the ClawMerchants catalog:

curl https://clawmerchants.com/v1/data/defi-yields-live
# HTTP/2 402
Enter fullscreen mode Exit fullscreen mode

The response body is structured for agents to parse:

{
  "status": 402,
  "protocol": "x402",
  "asset": {
    "id": "defi-yields-live",
    "name": "DeFi Yield Intelligence",
    "previewUrl": "https://clawmerchants.com/v1/preview/defi-yields-live",
    "guideUrl": "https://clawmerchants.com/learn/how-to-buy"
  },
  "payment": {
    "price": "0.005",
    "currency": "USDC",
    "chain": "base",
    "chainId": 8453,
    "recipient": "<provider-wallet>"
  },
  "instructions": {
    "method": "Include X-PAYMENT header with signed payment proof",
    "format": "base64-encoded JSON: { txHash, buyerWallet, buyerAgentId? }"
  },
  "catalog_url": "https://clawmerchants.com/.well-known/agent-catalog.json"
}
Enter fullscreen mode Exit fullscreen mode

The key things an agent needs to act on this:

  1. Price: 0.005 USDC — half a cent. Fits in any micropayment budget.
  2. Chain: Base L2. Fast finality, ~$0.001 gas per tx.
  3. previewUrl: Free data sample before committing. This matters.
  4. catalog_url: Machine-readable catalog of every available asset.

2. Preview Before Buying

The previewUrl pattern is the important one. Before a Cursor agent spends any USDC, it can fetch a sample of the actual data and decide if it's useful:

const preview = await fetch('https://clawmerchants.com/v1/preview/defi-yields-live');
const data = await preview.json();
Enter fullscreen mode Exit fullscreen mode

Response:

{
  "id": "defi-yields-live",
  "preview": {
    "sample": [
      {
        "protocol": "aerodrome-slipstream",
        "chain": "Base",
        "symbol": "USDC-VELVET",
        "apy": 17243.14,
        "tvlUsd": 247435,
        "riskTier": "high"
      },
      {
        "protocol": "supernova-cl",
        "chain": "Ethereum",
        "symbol": "USDC-WETH",
        "apy": 55379.57,
        "tvlUsd": 173291,
        "riskTier": "high"
      }
    ],
    "total_pools": 50,
    "preview_note": "Top 50 risk-ranked pools with APY, TVL, chain, and risk-adjusted yield delivered on payment"
  }
}
Enter fullscreen mode Exit fullscreen mode

The full paid response delivers 50 pools with APY, TVL, chain, and risk tier — live from DeFiLlama, refreshed every 5 minutes.

Same pattern for token anomaly alerts:

const alerts = await fetch('https://clawmerchants.com/v1/preview/token-anomalies-live');
Enter fullscreen mode Exit fullscreen mode
{
  "preview": {
    "sample": [
      {
        "symbol": "pepe",
        "anomalyType": ["rapid_move"],
        "priceChangePercent24h": 17.33,
        "currentPrice": 0.00000392,
        "detectedAt": "2026-03-16T16:18:23.099Z"
      }
    ],
    "total_anomalies": 10
  }
}
Enter fullscreen mode Exit fullscreen mode

An agent can evaluate these samples before deciding whether a purchase is relevant to its current task — then only buy when the data matches its decision criteria.


3. Paying with USDC on Base

Once the agent decides the data is worth buying, the flow is:

  1. Send a USDC transfer on Base to the recipient address
  2. Capture the txHash
  3. Re-call the data endpoint with an X-Payment header
import { ethers } from 'ethers';

const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
const RECIPIENT = '<recipient-from-402-body>';

// Sign and send USDC transfer
const provider = new ethers.JsonRpcProvider('https://mainnet.base.org');
const wallet = new ethers.Wallet(process.env.AGENT_PRIVATE_KEY!, provider);

const usdc = new ethers.Contract(USDC_BASE, [
  'function transfer(address to, uint256 amount) returns (bool)'
], wallet);

const tx = await usdc.transfer(RECIPIENT, ethers.parseUnits('0.005', 6));
const receipt = await tx.wait();

// Build payment proof
const paymentProof = Buffer.from(JSON.stringify({
  txHash: receipt.hash,
  buyerWallet: wallet.address,
  buyerAgentId: 'cursor-background-agent'
})).toString('base64');

// Fetch paid data
const response = await fetch('https://clawmerchants.com/v1/data/defi-yields-live', {
  headers: { 'X-Payment': paymentProof }
});

const pools = await response.json();
// => Full 50-pool response with APY/TVL/chain/riskTier
Enter fullscreen mode Exit fullscreen mode

No API keys. No rate limit negotiation. No billing dashboard. The payment is the auth.


4. Cursor Agent Commerce Protocol

The full discovery-to-purchase flow is what the cursor-agent-commerce-skill encodes. It's a SKILL.md behavioral protocol — a text document that gives a Cursor agent a structured 5-phase workflow:

  1. Discovery — detect 402 responses and parse the asset metadata
  2. Preview evaluation — fetch preview, assess relevance against task context
  3. Wallet setup — configure Base L2 wallet with appropriate balance
  4. Purchase execution — send USDC, capture txHash, build X-Payment header
  5. Data caching — cache purchased data with TTL to avoid redundant purchases

The skill includes decision criteria for when to buy (e.g., only if preview relevance score > threshold), cache invalidation logic, and error handling for failed transactions. It's priced at $0.05 — one-time purchase that makes any Cursor agent x402-capable.

Available at: GET /v1/data/cursor-agent-commerce-skill (or preview free at /v1/preview/cursor-agent-commerce-skill)


5. What's in the Catalog

The full machine-readable catalog lives at https://clawmerchants.com/.well-known/agent-catalog.json. Current live assets include:

Crypto/DeFi:

  • defi-yields-live — top 50 risk-ranked DeFi pools from DeFiLlama ($0.005/query, 5min refresh)
  • token-anomalies-live — real-time price anomalies from CoinGecko ($0.01/query, 5min)
  • security-intel-live — live CVEs from OSV.dev + NVD with CVSS scores ($0.02/query, 30min)
  • market-data-live — BTC/ETH/SOL/MATIC price + volume ($0.01/query, 5min)
  • crypto-sentiment-live — Fear & Greed Index + 7-day trend ($0.01/query, 30min)

Developer signals:

  • hn-top-stories-live — HN top stories with score/comments ($0.01/query, 5min)
  • hf-papers-live — daily AI papers from Hugging Face ($0.01/query, 30min)
  • github-trending-live — trending AI/agent repos with star velocity ($0.01/query, 60min)

Agent skills:

  • cursor-agent-commerce-skill — full x402 purchase protocol for Cursor agents ($0.05)
  • code-review-skill, security-audit-skill, defi-yield-strategy-skill, and 15+ more

Everything is priced in USDC fractions. The model: agents query what they need, pay for it per use, no subscriptions.


Try It Now

Free previews — no payment required:

# DeFi yields preview
curl https://clawmerchants.com/v1/preview/defi-yields-live

# Token anomaly alerts preview
curl https://clawmerchants.com/v1/preview/token-anomalies-live

# Full catalog (machine-readable)
curl https://clawmerchants.com/.well-known/agent-catalog.json
Enter fullscreen mode Exit fullscreen mode

The x402 Foundation — Cloudflare, Coinbase, and a growing ecosystem — is building the payment rails. The data and skills catalog is the supply side of what agents can buy.

Cursor agents can already discover, evaluate, and purchase from this catalog. The full protocol is in the skill.

Top comments (0)