Skip to content

eek-uniswap/mpp-uniswap-agent

Repository files navigation

mpp-uniswap-agent

One day, machines no longer needed human credit cards to pay for intelligence. An agent could walk up to any LLM endpoint, swap some ETH for stablecoins, and pay its way in. No accounts. No API keys. Just HTTP 402 and a receipt on-chain. This repo is one way that story begins. —March 2026

Autonomous agent payment demo: ETH → Uniswap → USDC → HTTP 402 → LLM inference. No API keys. No accounts. Just pay.

What it does

An autonomous agent holds ETH on Unichain, swaps to USDC via Uniswap V4, and pays for an LLM inference call using the Machine Payments Protocol (HTTP 402). The entire flow — swap, pay, receive response — happens in a single command with no human intervention.

Architecture

agent.ts                              server.ts
  │                                      │
  ├── Check USDC balance                 │
  │   └── Swap ETH→USDC (Uniswap V4)    │
  │                                      │
  ├── POST /v1/chat/completions ────────►│
  │◄── 402 Payment Required ────────────┤
  │                                      │
  ├── Transfer USDC on-chain             │
  │                                      │
  ├── Retry with Authorization ─────────►│── Verify tx on-chain
  │◄── 200 OK + Payment-Receipt ────────┤── Proxy to OpenRouter
  │                                      │
  └── Print response                     │

Quick start

# 1. Install
pnpm install

# 2. Configure server
cp .env.example .env
# Edit .env: OPENROUTER_API_KEY, SERVER_WALLET, HMAC_SECRET

# 3. (Testnet only) Ensure the ETH/USDC pool exists
pnpm run setup-pool

# 4. Start server
pnpm run server

# 5. Run agent (in another terminal)
pnpm run agent "Explain how autonomous agent payments work"
# First run auto-generates a wallet and saves the key to .env.
# Fund it with testnet ETH, then run again.

The agent only needs ETH — it generates its own wallet and swaps to USDC autonomously via Uniswap. That's the whole point.

Getting testnet ETH: QuickNode faucet or Superchain faucet

How it works

  1. Agent checks USDC balance; if low, swaps ETH→USDC via Uniswap V4 on Unichain
  2. Agent POSTs to the MPP server, gets HTTP 402 with a payment challenge
  3. Agent transfers USDC on-chain to fulfill the challenge
  4. Agent retries with the payment credential (tx hash)
  5. Server verifies the payment on-chain, proxies to OpenRouter, returns the LLM response with a Payment-Receipt

Links

  • MPP — Machine Payments Protocol (open standard for machine-to-machine payments)
  • Uniswap — Decentralized token exchange protocol
  • Unichain — L2 built for DeFi
  • OpenRouter — Unified API for LLM inference

License

MIT

About

Autonomous agent payment demo: ETH → Uniswap V4 → USDC → HTTP 402 (MPP) → LLM inference. No API keys. No accounts. Just pay.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors