Two autonomous AI agents that meet, negotiate a freelance job, deliver work, and settle payment on-chain — all powered by the @0xgasless/agent-sdk.
A startup founder (Agent A) and a freelance researcher (Agent B) go through a full business interaction autonomously:
- Networking — The agents introduce themselves at a blockchain industry event
- Discovery — The founder describes a research task they need done
- Negotiation — They agree on a price in USDT
- Work Delivery — The freelancer delivers a research brief
- On-chain Payment — The founder pays the freelancer via the x402 gasless payment protocol
- Closing — Both agents wrap up professionally
Every step uses real on-chain infrastructure:
| Feature | Standard | Contract |
|---|---|---|
| Agent Identity | ERC-8004 | 0x372d...99f |
| Payments | x402 Protocol | Gasless via facilitator relay |
| Token | USDT on Fuji | 0x40dA...7BA |
| Network | Avalanche Fuji | Chain ID 43113 |
┌─────────────────────────────────────────────────┐
│ Owner (You) │
│ 0xGas-managed embedded wallet │
│ Funds agents with AVAX + USDT │
└──────────┬─────────────────────┬────────────────┘
│ fund │ fund
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Agent A │ │ Agent B │
│ Employer │ │ Freelancer │
│ ethers.Wallet │ │ ethers.Wallet │
│ Signs autonomy │ │ Signs autonomy │
│ ERC-8004 ID: 17 │ │ ERC-8004 ID: 18 │
└────────┬─────────┘ └─────────┬───────┘
│ │
│ x402 payment │
└───────────────────────┘
Three wallets, three roles:
| Wallet | Key Management | Purpose |
|---|---|---|
| Owner | @0xgasless/core (KMS-backed) | Authenticate, fund agents, withdraw earnings |
| Agent A | ethers.Wallet in localStorage |
Autonomous signing for registration + payments |
| Agent B | ethers.Wallet in localStorage |
Autonomous signing for registration + receiving |
Agent wallets are generated once and persisted in localStorage so they survive page refreshes. The owner funds them explicitly — agents only hold what you give them.
- React + TypeScript + Vite — Frontend framework
- Tailwind CSS + Shadcn UI — Styling and components
- @0xgasless/core — Secure embedded wallet SDK (email/social login)
- ethers.js v6 — Blockchain interaction
- @0xgasless/agent-sdk — Agent identity (ERC-8004) and gasless payments (x402)
- OpenRouter — AI conversation engine (GPT-4o-mini)
- Bun (or Node.js 18+)
- A 0xGas API key (free tier works)
- An OpenRouter API key
- Testnet AVAX from the Avalanche Faucet
cd agent-frontend-demo
bun installcp .env.example .envEdit .env with your keys:
VITE_PRIVY_APP_ID=your-privy-app-id
VITE_OPENROUTER_API_KEY=your-openrouter-api-key
bun run devOpen http://localhost:5173 in your browser.
- Log in with email via 0xGas embedded wallet
- Fund agents — Use the sidebar buttons to send AVAX (for gas) and USDT (for payments) to each agent
- Register agents — Each agent mints an ERC-8004 identity NFT on Fuji
- Start conversation — Watch the agents network, negotiate, deliver work, and pay each other
- Withdraw funds — Transfer agent earnings back to your owner wallet
src/
├── App.tsx # Main app — layout, conversation loop, wallet management
├── hooks/
│ └── useAgent.ts # Agent hook — SDK integration, AI prompts, payment logic
├── services/
│ └── openrouter.ts # OpenRouter API client
├── config/
│ └── fuji.ts # Network config (re-exports from SDK)
├── types/
│ └── agent.ts # TypeScript interfaces
├── components/ui/ # Shadcn components (button, card, badge, alert)
├── lib/
│ └── utils.ts # Tailwind class merge utility
├── index.css # Tailwind + custom theme variables
└── main.tsx # Entry point with PrivyProvider
Each agent registers on-chain by minting an NFT on the Identity Registry contract. This gives them a unique Agent ID that acts as their verifiable identity. Registration is checked on every page load using direct balanceOf + ownerOf view calls (no event logs, works with any RPC).
When Agent A pays Agent B:
- Agent A signs an EIP-712 payment authorization off-chain
- The payload is sent to the x402 facilitator for verification
- The facilitator settles the payment on-chain via the relayer contract
- Agent B receives USDT — no gas needed for the payment itself
The conversation uses phase-based system prompts (networking → discovery → negotiation → delivery → payment) with strict guardrails:
- Agents cannot roleplay the other party
- Agents cannot skip phases or defer work to "later"
- Payment amounts are capped to the agent's actual balance
- Conversation terminates cleanly after payment
| Variable | Required | Description |
|---|---|---|
VITE_0XGAS_API_KEY |
Yes | Your 0xGas application API key |
VITE_OPENROUTER_API_KEY |
Yes | OpenRouter API key for AI conversations |
| Contract | Address |
|---|---|
| Identity Registry (ERC-8004) | 0x372d406040064a9794d14f3f8fec0f2e13e5b99f |
| USDT Token | 0x40dAE5db31DD56F1103Dd9153bd806E00A2f07BA |
MIT