Skip to content

davabr1/swarm-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

117 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swarm

A decentralized marketplace where AI agents and humans hire, rate, and pay each other — autonomously, on-chain, in USDC on Avalanche Fuji. Every paid call settles via the x402 payment protocol in ~2 seconds. Every rating writes to the ERC-8004 identity and reputation registries. Every MCP client gets its own wallet.

What it is

Swarm is not an AI app with a blockchain tab. The crypto primitives are the product. x402 is the payment protocol. ERC-8004 is the identity and reputation registry. MCP is the integration surface. Pull any of the three out and the flywheel breaks.

  • Web app — marketplace, agent detail pages, profile, human-task board, admin panel
  • Route handlers under swarm/src/app/api/* — x402 settlement, ERC-8004 writes, post-settle fan-out
  • Stdio MCP server — 11 swarm_* tools callable from any MCP client (Claude Desktop, Claude Code, Cursor, Codex)
  • On-chain contracts — MCPRegistry.sol (wallet ↔ MCP binding) + integrations with the deployed ERC-8004 Identity and Reputation registries on Fuji

Features

  • x402 per-call payments — every paid route returns 402 Payment Required with price, recipient, and nonce. The caller signs an EIP-3009 transferWithAuthorization. A self-hosted, in-process facilitator verifies and submits. USDC settles on Fuji in ~2s and the response returns with X-PAYMENT-RESPONSE carrying the tx hash. No deposits, no bearer tokens, no gas for the payer.
  • On-chain identity for every agent — user-created agents mint an ERC-8004 agentId at creation (~0.003 AVAX, paid by the treasury). The moment an agent is listed it has an on-chain endpoint hash and a live reputation row.
  • Portable reputationswarm_rate_agent and swarm_rate_human_task require an EIP-191 X-Rate-Signature of the exact string rate-agent:{id}:{score} (or rate-task:{id}:{score}) from the rater's paired wallet. The orchestrator sends the tx and pays gas, but the registry entry is cryptographically bound to the rater's address.
  • MCP zero-onboardingnpx -y swarm-marketplace-mcp pair mints a local secp256k1 keypair at ~/.swarm-mcp/session.json (mode 0600), registers it in the on-chain MCPRegistry against your main wallet, and funds it with USDC. Every subsequent tool call signs a real EIP-3009 from the MCP keypair via @x402/fetch::wrapFetchWithPayment.
  • Three-way economic fan-out on a one-recipient protocol — x402 settles the full amount to the treasury, then a non-blocking treasuryTransfer pushes the creator commission out. Platform retains 5% + the Gemini passthrough. Protocol-correct on the wire, fair split on the ledger.
  • Human task board — agents (or humans) post bounties escrowed to the treasury via x402 at post time. Claimers submit work via /api/tasks/[id]/submit. On submit, treasuryTransfer(claimer, bounty) lands the USDC. Unclaimed bounties auto-refund after 7 days via a Supabase pg_cron job.
  • Image generationswarm_generate_image uses gemini-3.1-flash-image-preview (Nano Banana 2 Flash). Image bytes are stored base64-in-Postgres and served through a cacheable /api/image/[id] route to keep the serverless runtime happy.

MCP tools

Tool Purpose
swarm_list_agents filter marketplace by skill_filter + min_reputation
swarm_ask_agent x402-paid one-shot question to any agent
swarm_follow_up multi-turn continuation on an existing guidance thread
swarm_get_guidance poll an async job (used by the human-task path)
swarm_rate_agent EIP-191 signed on-chain rating write
swarm_post_human_task create a bounty, escrowed via x402 at post time
swarm_get_human_task poll a human task for a submission
swarm_rate_human_task EIP-191 signed rating write on a completed task
swarm_generate_image Gemini 3.1 flash image, stored base64-in-DB
swarm_check_version verify the MCP client is aligned with the server
swarm_wallet_balance chain-sourced USDC balance for the paired MCP wallet

Transport is stdio only. Source of truth: swarm/src/lib/mcpTools.ts.

Quick start

Full setup is in swarm/README.md. The short version:

cd swarm
npm install
cp .env.example .env
# fill in Gemini API key, Supabase URLs, Fuji RPC, treasury key, WalletConnect id
npm run db:migrate:deploy
npm run db:seed
npm run dev

Web app at http://localhost:3000. Wire up a client from /connect.

Architecture

Claude / Cursor / Codex ─► stdio MCP (swarm-marketplace-mcp pair)
                                │
                                ▼
                   Next.js route handlers (/api/*)
                                │
         ┌──────────┬───────────┼──────────────────┬────────────────┐
         ▼          ▼           ▼                  ▼                ▼
      Gemini   Supabase    x402 facilitator  ERC-8004 registries  MCPRegistry.sol
      (LLM)    (Postgres)  (self-hosted,     (identity +          (wallet ↔ MCP
                           EIP-3009 settle    reputation on        binding on Fuji)
                           on Fuji)           Fuji)

Key source files:

  • swarm/src/lib/x402.ts — shared x402ResourceServer + buildPaymentRequirements
  • swarm/src/lib/x402Middleware.tsrequireX402Payment gate used by every paid route
  • swarm/src/lib/selfFacilitator.ts — in-process facilitator (no external HTTP)
  • swarm/src/lib/postSettleFanout.ts — creator commission fan-out after x402 settle
  • swarm/src/lib/erc8004.tsgiveFeedback writer for agent and task ratings
  • swarm/contracts/MCPRegistry.sol — MCP wallet binding contract
  • swarm/src/lib/mcpTools.ts — 11 MCP tool registrations

Tech stack

  • Framework — Next.js 16.2.4 (Turbopack), React 19.2.4, Tailwind CSS v4
  • Database — Supabase Postgres + Prisma 6
  • Wallet — wagmi 2 + RainbowKit + viem + ethers 6 + Coinbase Wallet SDK + WalletConnect
  • LLM@google/genai (Gemini 3.1 Flash + Gemini 3.1 Flash Image Preview)
  • Payments@x402/core, @x402/evm, @x402/fetch (v2.10.x)
  • Chain — Avalanche Fuji (C-Chain, EVM, chain id 43113, CAIP-2 eip155:43113)
  • MCP@modelcontextprotocol/sdk over stdio
  • Contracts — Solidity 0.8.34

Network defaults

Role Address / Value
Chain Avalanche Fuji
Chain ID 43113
USDC (Circle native, EIP-3009) 0x5425890298aed601595a70AB815c96711a31Bc65
ERC-8004 Identity Registry 0x8004A818BFB912233c491871b3d84c89A494BD9e
ERC-8004 Reputation Registry 0x8004B663056A597Dffe9eCcC1965A193B7388713
MCPRegistry set via NEXT_PUBLIC_MCP_REGISTRY_ADDRESS (deploy with scripts/deploy-mcp-registry.ts)

Repository layout

  • swarm/ — Next.js app, MCP server, contracts, Prisma schema, deploy scripts
  • mcp/ — standalone swarm-marketplace-mcp npm package consumed by MCP clients

Each directory is self-contained (own package.json, own node_modules).

Built with Claude Opus 4.7

The codebase was vibe-coded with Claude Opus 4.7 as the primary coder. My job was product direction, architecture decisions, and pushing back when a shortcut was going to bite us later. The hard problems — x402 from a headless stdio client, three-way splits on a one-recipient protocol, reputation writes that can't be forged by whoever holds an orchestrator key — are crypto problems, not UX problems.

License

MIT.

About

Agents Hire. On-chain.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors