{"id":51529465,"url":"https://github.com/bh2smith/x402-swarm-agent","last_synced_at":"2026-07-09T01:01:43.515Z","repository":{"id":366144894,"uuid":"1275188836","full_name":"bh2smith/x402-swarm-agent","owner":"bh2smith","description":"x402-paywalled token data agent with encrypted, verifiable Swarm receipts (clean fork of bh2smith/price-agent)","archived":false,"fork":false,"pushed_at":"2026-06-20T13:00:34.000Z","size":1422,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-20T14:15:50.989Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bh2smith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-20T11:17:31.000Z","updated_at":"2026-06-20T13:00:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bh2smith/x402-swarm-agent","commit_stats":null,"previous_names":["bh2smith/x402-swarm-agent"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/bh2smith/x402-swarm-agent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bh2smith%2Fx402-swarm-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bh2smith%2Fx402-swarm-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bh2smith%2Fx402-swarm-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bh2smith%2Fx402-swarm-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bh2smith","download_url":"https://codeload.github.com/bh2smith/x402-swarm-agent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bh2smith%2Fx402-swarm-agent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35282899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-08T02:00:06.796Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-07-09T01:01:42.467Z","updated_at":"2026-07-09T01:01:43.479Z","avatar_url":"https://github.com/bh2smith.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# x402 Swarm Agent\n\nA token-data API that is **paywalled with [x402](https://x402.org) (USDC on Base)** and writes an\n**encrypted, verifiable receipt of every paid request to [Swarm](https://www.ethswarm.org/)**.\n\nPay a few hundredths of a cent in USDC, get a token price back, and a tamper-evident record of\n`(payer, payment, request, response)` is appended to an on-Swarm, append-only chain — with the response\nstored encrypted so only the paying caller can read it.\n\n**Live:** https://x402-swarm-agent.vercel.app\n\u0026nbsp;·\u0026nbsp; **Swagger UI:** https://x402-swarm-agent.vercel.app/\n\n\u003e Provenance: a clean fork of [`bh2smith/price-agent`](https://github.com/bh2smith/price-agent), with the\n\u003e Bitte coupling removed, x402 upgraded to v2 (`@x402/*`), and the Swarm receipt layer added.\n\n## How it works\n\n```\nclient ──GET /api/tools/prices──▶  x402 middleware (proxy.ts)\n                                     │  no payment? → 402 PAYMENT-REQUIRED\n                                     │  paid (PAYMENT-SIGNATURE)? → settle via CDP facilitator\n                                     ▼\n                              price handler (FeedRevolver: CoinGecko / DeFiLlama /\n                                     │                      DexScreener / Alchemy / Zerion)\n                                     ▼\n                              encrypt response → Swarm  ─┐\n                              append receipt to feed ────┤ lib/swarm\n                                     │                    │\n                       200 + price + X-RECEIPT ◀──────────┘  (payer's decrypting ref)\n```\n\n- **Paywall** — `src/proxy.ts` uses x402 v2 (`@x402/next` `paymentProxy` + `@x402/evm` exact scheme +\n  Coinbase CDP facilitator) to charge USDC per request on Base.\n- **Prices** — `lib/prices/` aggregates multiple sources with fallback (`FeedRevolver`).\n- **Receipts** — `lib/swarm/` encrypts the response to Swarm, commits the bare content address in a\n  public, `prevHash`-linked receipt on the `agent-receipts` feed, and returns the payer's full\n  decrypting reference in the `X-RECEIPT` response header. Best-effort: a Swarm failure never blocks\n  the paid response.\n\n## Endpoints\n\n| Route | Description |\n|---|---|\n| `GET /api/tools/prices?address=\u003ctoken\u003e\u0026chainId=\u003cid\u003e` | x402-paywalled token price → `{ price, source }` (+ `X-RECEIPT`) |\n| `POST /api/tools/query` `{ prompt }` | **AI data analyst** — a Claude agent writes \u0026 runs DuneSQL via the Dune MCP and returns a written answer. Paid with x402 `upto` (billed for actual usage). |\n| `GET /api/ai-plugin` | OpenAPI 3.0 spec for the agent |\n| `GET /` | Demo UI (price lookups + the analyst); Swagger at `/docs` |\n\n## Quick start\n\n```bash\nbun install\ncp .env.example .env          # fill in keys — see .env.example and DEPLOY.md\nbun run dev                   # next dev on http://localhost:3000\n```\n\nOther scripts: `bun run build` · `bun run start` · `bun test` · `bun run fmt`.\n\n### Calling a paid endpoint\n\nA v2 client helper lives in [`example/x402-payment-handler.ts`](./example/x402-payment-handler.ts):\n\n```ts\nimport { withPayment } from \"./example/x402-payment-handler\";\n\n// Needs a funded EOA (USDC + a little gas) on the target network.\nconst res = await withPayment(\n  \"https://x402-swarm-agent.vercel.app/api/tools/prices?address=0x...\u0026chainId=8453\",\n  process.env.PAYER_PRIVATE_KEY as `0x${string}`,\n);\nconsole.log(await res.json(), res.headers.get(\"x-receipt\"));\n```\n\n### Verifying the receipt chain\n\n`script/receipt-e2e.ts` records receipts and walks the chain (encryption + links + payment decode):\n\n```bash\nBEE_FEED_PK=\u003chex\u003e BEE_FEED_TOPIC=\"e2e-$(date +%s)\" bun run script/receipt-e2e.ts\n```\n\n## Configuration \u0026 deployment\n\nAll credentials (data sources, x402/CDP payments, Swarm) and a Vercel deployment plan are documented in\n**[DEPLOY.md](./DEPLOY.md)**. See **[.env.example](./.env.example)** for the full env list. In short:\n\n- **Data:** `ALCHEMY_KEY`, `ZERION_KEY` (optional — keyless sources also work)\n- **Payments:** `ADDRESS` (payTo), `NETWORK` (CAIP-2, e.g. `eip155:8453`), `USE_CDP_FACILITATOR=true`,\n  `CDP_API_KEY_ID`, `CDP_API_KEY_SECRET`\n- **Receipts:** `BEE_FEED_PK` (required); `BEE_URL` / `BEE_POSTAGE_BATCH_ID` / `BEE_FEED_TOPIC` (optional;\n  the public gateway works out of the box)\n\n## Tech stack\n\nNext.js 16 · TypeScript · x402 v2 (`@x402/next`, `@x402/core`, `@x402/evm`) · `@coinbase/x402` CDP\nfacilitator · viem · `@ethersphere/bee-js` (Swarm) · zod.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbh2smith%2Fx402-swarm-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbh2smith%2Fx402-swarm-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbh2smith%2Fx402-swarm-agent/lists"}