x402-weather-agent

agent
Guvenlik Denetimi
Uyari
Health Uyari
  • License — License: MIT
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 6 GitHub stars
Code Uyari
  • network request — Outbound network request in src/briefing.ts
  • network request — Outbound network request in src/buy-usdt.ts
Permissions Gecti
  • Permissions — No dangerous permissions requested

Bu listing icin henuz AI raporu yok.

SUMMARY

An agent that buys data and sells weather briefings per request over x402 on Celo, paying from an Altana smart wallet.

README.md

x402 Weather Agent

An agent that pays per request for weather data over x402 on Celo - and sells its briefing the same way.

Built for Celo's Agents Open for Business hackathon (Nov 20 - Dec 7, 2026), Altana Smart Agentic Wallets track. Live on Celo mainnet.

Demo video: https://youtu.be/CAu6qM8U3js
Live demo: https://x402-weather-agent.onrender.com

What it does

A real person (pedi) needs a daily weather briefing to trade Polymarket weather markets. This agent does that job end to end, paying its own way:

  1. Buys forecast data per request over x402, from its own Altana smart wallet - under a session key with a spend cap, a contract allowlist, and an expiry granted by its owner. No keys, no subscriptions.
  2. Sells the finished briefing per request over x402 ($0.01 USDC or USDT).
  3. Registers itself on ERC-8004 so other agents can discover and rate it.
  4. Tags its direct transactions with an ERC-8021 attribution suffix (tagged tx). Relay transactions and x402 settlements cannot carry the tag yet; see design notes.

Live on mainnet

  • Agent wallet (Altana smart wallet): 0x604052C4C5E1b179B24F470aC9eBdFcC2E8ADc51
  • ERC-8004 agent ID: 10170 - registration tx
  • Session: granted to a saved session key, expires 2026-12-12T13:37:57Z (renewed 2026-12-05); spend caps $0.10/day USDC + $0.10/day USDT, 0.1 CELO/day gas.
  • Attribution tag: celo_94e8e232cbb1

Proven live (both sides, mainnet, Nov 28 2026)

  • Buy: the agent paid $0.01 USDT to buy for Chainstack Celo RPC data via its session - settlement tx (block 83971791), real RPC result returned.
  • Sell: the seller sold a real NYC briefing for $0.01 USDT to a third-party buyer - settlement tx (block 83972164).

Public endpoints (for agents)

Base URL: https://x402-weather-agent.onrender.com (Celo mainnet, eip155:42220).

Hosted on Render's free tier: after ~15 min idle the instance sleeps and the first request takes ~30-60 s while it wakes (measured 32.8 s on 2026-12-05). Use a client timeout of at least 90 s for the first call; after that responses take well under a second.

Route Payment What it returns
GET / free Landing page in a browser; JSON service info (network, price, payTo, routes, cities) for agents and curl. ?format=json forces JSON
GET /health free {"ok":true,...} liveness probe, no upstream calls
GET /briefing?city=NYC x402, $0.01 (USDC 0xcebA9300f2b948710d2653dD7B07f33A8B32118C or USDT 0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e, scheme exact, EIP-3009) JSON weather briefing for one city: current temperature, today's and tomorrow's high and low, chance of rain. Unknown cities get a free 400 before any payment is asked

Cities (case-insensitive): NYC, Chicago, Miami, Houston, LA, Boston, SF, Denver, Seattle, Atlanta, London, Toronto. US cities are in Fahrenheit, London and Toronto in Celsius. Forecasts are cached for 10 minutes. Payments go to the agent wallet 0x604052C4C5E1b179B24F470aC9eBdFcC2E8ADc51; the Celo x402 facilitator (https://api.x402.celo.org) verifies and settles.

How an agent buys a briefing

  1. GET /briefing?city=NYC -> 402 Payment Required. The base64 JSON in the PAYMENT-REQUIRED header lists the accepts options (network, asset, amount: "10000" = $0.01 at 6 decimals, payTo, EIP-712 domain in extra).
  2. Sign an EIP-3009 TransferWithAuthorization for one option and retry the same URL with the PAYMENT-SIGNATURE header (any x402 v2 client does this for you).
  3. -> 200 with the briefing JSON and a base64 PAYMENT-RESPONSE header carrying the settlement tx hash.
# free
curl --max-time 90 https://x402-weather-agent.onrender.com/health
# see the payment requirements
curl -si --max-time 90 "https://x402-weather-agent.onrender.com/briefing?city=NYC" | grep -i payment-required
# pay and fetch with the bundled x402 client (needs a funded BUYER_PRIVATE_KEY in .env)
X402_NETWORK=mainnet npx tsx src/buyer.ts "https://x402-weather-agent.onrender.com/briefing?city=NYC"
import { x402Client, wrapFetchWithPayment } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm/exact/client";
const client = new x402Client().register("eip155:*", new ExactEvmScheme(account));
const res = await wrapFetchWithPayment(fetch, client)("https://x402-weather-agent.onrender.com/briefing?city=NYC");

Hosting notes: start command npm start (= tsx src/seller.ts); the server binds 0.0.0.0 and process.env.PORT; health check path /health. Env: X402_NETWORK=mainnet, SELLER_PAY_TO, X402_API_KEY. Behind a proxy the resource URL in the 402 response is built from X-Forwarded-Proto / X-Forwarded-Host; set PUBLIC_BASE_URL (for example https://x402-weather-agent.onrender.com) if your proxy does not send them.

Tests

npm test        # 20 tests, offline: no secrets, no RPC, facilitator and weather APIs mocked
npm run build   # tsc --noEmit over src/ and test/
  • test/x402-payment.test.ts - full x402 loop in-process: free routes answer without the facilitator, 402 challenge (USDC + USDT), the buyer signs a real EIP-3009 authorization that the mock facilitator recovers with EIP-712, verify -> settle -> 200 + PAYMENT-RESPONSE; rejected payments are not served or settled; unknown cities get a 400 before any 402; an upstream failure returns 502 and is not settled; / serves HTML to browsers and JSON to agents; buyer spend caps refuse over-priced options.
  • test/agent-briefing.test.ts - the agent's briefing builder: Open-Meteo parsing, Celsius for London and Toronto, NWS fallback for US cities, cache, error paths.
  • test/sepolia.test.ts - default testnet config offers USDC only.
  • test/public-url.test.ts - https resource URL behind a proxy.

CI (.github/workflows/ci.yml) runs build, tests, and npm audit --omit=dev on every push and PR.

Stack

  • Celo mainnet (Sepolia testnet first) · x402 v2 (@x402/hono, @x402/fetch, @x402/evm)
  • Altana smart wallets (@altananetwork/sdk + viem)
  • ERC-8004 identity registry · @celo/attribution-tags

Run it

npm install
# fill in .env (never commit it): AGENT_ADMIN_PRIVATE_KEY, AGENT_SESSION_PRIVATE_KEY,
# SELLER_PAY_TO, X402_API_KEY, BUYER_PRIVATE_KEY
# Mainnet setup: register ERC-8004 identity + grant the session
X402_NETWORK=mainnet npx tsx src/setup.ts
# Approve the session's signature checkers (USDC + USDT)
X402_NETWORK=mainnet npx tsx src/approve-checker.ts
# Sell briefings (binds 0.0.0.0:$PORT, default 3000)
X402_NETWORK=mainnet npm start
# Buy a briefing as a third-party buyer
X402_NETWORK=mainnet npx tsx src/buyer.ts http://localhost:3000/briefing?city=NYC
# Buy a buy route with the agent's session ($0.01 USDT)
X402_NETWORK=mainnet npx tsx src/buy-usdt.ts

X402_NETWORK defaults to testnet (Celo Sepolia); set it to mainnet for chain 42220. See docs/DESIGN.md for the design decisions and what each script does.

License

MIT

Yorumlar (0)

Sonuc bulunamadi