Decentralized AI Agent Marketplace - A full-stack Web3 application for buying, selling, and executing AI agents on the blockchain.
ββββββββββββββββββββββββββββ
β React UI β
β wagmi + ethers.js β
ββββββββββββββ¬ββββββββββββββ
β
Wallet Connect / Buy
β
ββββββββββββββΌββββββββββββββ
β Smart Contract β
β AgentMarket.sol β
ββββββββββββββ¬ββββββββββββββ
β Events
ββββββββββββββββΌββββββββββββββββ
β The Graph β
β (Indexes AgentPurchased evt) β
ββββββββββββββββ¬ββββββββββββββββ
β GraphQL
ββββββββββββββΌβββββββββββββββ
β React Analytics β
β (Purchases, revenue etc.) β
ββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββ
β Node.js Backend β
β Express + Postgres + JWT β
β Server-side TX (optional) β
ββββββββββββββββββββββββββββββ
- React + TypeScript + Vite - Fast, modern development
- wagmi + ethers.js - Ethereum wallet integration
- Zustand - State management
- Tailwind CSS - Styling
- React Query - Data fetching
- Node.js + Express + TypeScript
- PostgreSQL (pg) - Database
- JWT - Authentication (wallet sign-in)
- Socket.io - Real-time updates
- ethers.js - Event listening & server-side transactions
- Solidity - Smart contracts
- Hardhat - Development environment
- Alchemy - RPC provider & WebSocket
- The Graph - Event indexing
- Node.js >= 18
- PostgreSQL >= 14
- MetaMask or compatible wallet
- Alchemy account (free tier works)
git clone <your-repo>
cd AgentMart
npm run install:allcp .env.example .env
# Edit .env with your valuesRequired variables:
ALCHEMY_API_KEY- Get from AlchemyDATABASE_URL- PostgreSQL connection stringJWT_SECRET- Random secret for JWT signingRELAY_PRIVATE_KEY- Private key for server-side transactions (optional)
# Create database
createdb agentmart
# Run migrations
npm run migrate:db
# Seed with sample agents
npm run seed:db# Option A: Local Hardhat network (for development)
cd contracts
npx hardhat node # Keep running in separate terminal
npx hardhat run scripts/deploy.ts --network localhost
# Option B: Testnet (Sepolia)
npx hardhat run scripts/deploy.ts --network sepoliaCopy the deployed contract address to .env as CONTRACT_ADDRESS.
# Start all services (frontend, backend, listener)
npm run dev:start
# Or start individually:
npm run dev:frontend # http://localhost:5173
npm run dev:backend # http://localhost:3001
npm run dev:listener # Event listener- Ensure all services are running (
npm run dev:start) - Open http://localhost:5173 in browser
- Have MetaMask installed and connected to Sepolia testnet
Step 1: Connect Wallet
- Click "Connect Wallet" button
- Approve MetaMask connection
- Click "Sign In" to authenticate with backend
- See your address displayed
Step 2: Browse Agents
- View list of AI agents with descriptions and prices
- Click on an agent card to see details
- Example: "Code Review Agent" - 0.001 ETH
Step 3: Purchase Agent
- Click "Buy Agent" button
- Choose purchase method:
- Client-side: You pay gas (MetaMask popup)
- Server-relay: Server pays gas (faster, sponsored)
- Confirm transaction
Step 4: Watch Transaction
- See transaction hash and Etherscan link
- Backend listener detects
AgentPurchasedevent - Order status updates: Pending β Confirmed
- Real-time toast notification via Socket.io
Step 5: View Result
- Order marked as "Confirmed" in your purchases
- Agent execution result displayed (or mock data)
- Transaction visible on Etherscan
Optional: The Graph Query
- View analytics dashboard
- GraphQL query shows all purchases, total revenue
- Indexed from blockchain events
AgentMart/
βββ frontend/ # React + Vite app
β βββ src/
β β βββ components/ # UI components
β β β βββ WalletConnect.tsx
β β β βββ AgentList.tsx
β β β βββ AgentDetail.tsx
β β β βββ BuyButton.tsx
β β βββ state/ # Zustand store
β β βββ utils/ # ethers.js helpers
β β βββ api.ts # API client
β β βββ App.tsx
β βββ package.json
β βββ vite.config.ts
β
βββ backend/ # Express API
β βββ src/
β β βββ routes/ # API endpoints
β β β βββ auth.ts # Wallet sign-in
β β β βββ agents.ts # Agent CRUD
β β β βββ purchase.ts # Order management
β β βββ db/ # PostgreSQL client
β β βββ listener.ts # Event listener (Alchemy WS)
β β βββ relayer.ts # Server-side signer
β β βββ index.ts # Express app
β βββ package.json
β
βββ contracts/ # Solidity + Hardhat
β βββ contracts/
β β βββ AgentMarket.sol
β βββ scripts/
β β βββ deploy.ts
β βββ test/
β β βββ AgentMarket.test.ts
β β βββ gas-usage.test.ts
β βββ abi/
β β βββ AgentMarket.json
β βββ hardhat.config.ts
β
βββ subgraph/ # The Graph indexing
β βββ schema.graphql
β βββ subgraph.yaml
β βββ mappings/
β βββ mapping.ts
β
βββ scripts/ # Database & deployment
β βββ migrate.sql
β βββ seed_agents.sql
β βββ deploy_contract.sh
β
βββ .env.example
βββ package.json
βββ README.md
1. Client-Side Purchase (User pays gas)
// Frontend signs transaction
const tx = await contract.purchase(agentId, { value: price });
// Backend records order with txHash
await fetch('/api/purchase', {
method: 'POST',
body: { agentId, txHash: tx.hash }
});2. Server-Relay Purchase (Server pays gas - sponsored experience)
// Frontend requests purchase
const { txHash } = await fetch('/api/purchase', {
method: 'POST',
body: { agentId, amount }
});
// Backend signs & sends transaction with RELAY_PRIVATE_KEY- Smart Contract emits
AgentPurchasedevent - Listener Service (Alchemy WebSocket) catches event
- Database updated with confirmation
- Socket.io pushes update to frontend
- The Graph indexes for analytics
cd contracts
# Run all tests
npm test
# Gas usage analysis
npm run test:gas
# Coverage
npm run coveragecd backend
npm test# Deploy to Sepolia testnet
cd contracts
npm run deploy:sepolia
# Verify on Etherscan
npx hardhat verify --network sepolia <CONTRACT_ADDRESS>cd backend
npm run build
# Deploy to your preferred platform:
# - Railway, Render, Fly.io for Node.js
# - Configure DATABASE_URL for production PostgreSQLcd frontend
npm run build
# Deploy to Vercel, Netlify, or Cloudflare Pages
# Set environment variables in hosting platform# Authenticate with The Graph Studio
graph auth --studio <DEPLOY_KEY>
# Deploy subgraph
npm run subgraph:codegen
npm run subgraph:build
npm run subgraph:deploy- Never commit private keys - Use environment variables
- Rotate JWT secrets - Use strong, random values
- Limit relayer funds - Use dedicated wallet with minimal ETH
- Validate inputs - Add rate limiting, input sanitization
- Use HTTPS - Enable SSL/TLS in production
- Database security - Use connection pooling, prepared statements
- Audit contracts - Get professional audit before mainnet
POST /api/auth/sign-message
{ "address": "0x..." }
β { "message": "Sign this message to authenticate: <nonce>" }POST /api/auth/verify
{ "address": "0x...", "signature": "0x..." }
β { "token": "jwt_token_here" }GET /api/agents
β [{ "id": 1, "name": "Code Review Agent", "price": "0.001", ... }]GET /api/agents/:id
β { "id": 1, "name": "Code Review Agent", "description": "...", "price": "0.001" }POST /api/purchase (Authenticated)
// Client-side purchase
{ "agentId": 1, "txHash": "0x..." }
// Server-relay purchase
{ "agentId": 1, "amount": "0.001" }
β { "orderId": 123, "txHash": "0x...", "status": "pending" }GET /api/orders/:id (Authenticated)
β { "id": 123, "status": "confirmed", "txHash": "0x...", "agent": {...} }- WalletConnect: Wallet connection, sign-in flow
- AgentList: Browse available AI agents
- AgentDetail: View agent details, purchase
- BuyButton: Purchase flow (client or relay)
- ToastNotification: Real-time transaction updates
# Check PostgreSQL is running
pg_ctl status
# Verify connection string
psql $DATABASE_URL# Check network configuration in hardhat.config.ts
# Verify ALCHEMY_API_KEY is set
# Ensure deployer wallet has ETH for gas# Install MetaMask extension
# Switch to correct network (Sepolia)
# Check VITE_CONTRACT_ADDRESS in frontend/.env# Verify ALCHEMY_API_KEY supports WebSockets
# Check CONTRACT_ADDRESS is correct
# Ensure contract has Purchase events emittedINSERT INTO agents (name, description, price, category)
VALUES ('New Agent', 'Description', 0.001, 'Development');# Terminal 1: Start local node
npx hardhat node
# Terminal 2: Deploy & test
npx hardhat run scripts/deploy.ts --network localhost
npx hardhat test --network localhost# Backend listener logs all events
npm run dev:listener
# Or manually test with ethers.js
node scripts/test-listener.js- Implement actual OpenAI agent execution
- Add agent rating/review system
- Support multiple payment tokens (ERC-20)
- Gas optimization in smart contract
- Add agent marketplace curation
- Implement dispute resolution
- Mobile responsive UI improvements
- Add agent execution history dashboard
- Support batch purchases
- Implement agent versioning