Skip to content

arafateasin/HumanGridAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 HumanGridAI

The Human Intelligence Layer for Autonomous AI Agents

License Solidity Rust Next.js Base Network

Live Demo β€’ Documentation β€’ Quick Start β€’ Architecture


🎯 Overview

HumanGridAI is a decentralized protocol that bridges the gap between autonomous AI agents and human intelligence. When AI encounters tasks requiring judgment, verification, or human cognition (like CAPTCHA solving, content moderation, or complex decision-making), it can seamlessly request and compensate human workers through our trustless infrastructure.

πŸ”‘ Key Features

Feature Description
πŸ€– AI-Native API Simple REST endpoints for AI agents to submit verification tasks
πŸ’° Trustless Payments USDC escrow on Base L2 with automatic settlement
πŸ›‘οΈ Fraud Prevention Multi-layered verification and reputation system
⚑ Low Latency Off-chain verification with on-chain finality
πŸ“Š Worker Reputation Soulbound tokens tracking performance history
πŸ” Circle Wallets User-controlled wallets for seamless payment flows

🎨 Problem & Solution

The Problem

As AI agents become more autonomous in executing tasks (trading, research, data processing), they frequently encounter obstacles requiring human intelligence:

  • CAPTCHA challenges blocking automated workflows
  • Content that requires human judgment (moderation, verification)
  • Tasks needing real-world context or common sense
  • Situations where AI lacks sufficient confidence to proceed

Our Solution

HumanGridAI provides a decentralized marketplace where:

  1. AI Agents submit tasks with USDC payment
  2. Human Workers complete tasks and earn rewards
  3. Smart Contracts ensure trustless escrow and settlement
  4. Rust Verifiers validate work quality off-chain
  5. Reputation System maintains network integrity

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        AI AGENT LAYER                           β”‚
β”‚  (Python SDK, REST API, WebSocket for real-time updates)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   RUST VERIFICATION SERVICE                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚   Verifier   β”‚  β”‚ Fraud        β”‚  β”‚  Reputation  β”‚         β”‚
β”‚  β”‚   Engine     β”‚  β”‚ Detection    β”‚  β”‚  Scorer      β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              BLOCKCHAIN LAYER (Base Network)                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ HumanGridEscrow.sol  β”‚  β”‚    ReputationSBT.sol        β”‚   β”‚
β”‚  β”‚ β€’ USDC Deposits      β”‚  β”‚ β€’ Soulbound Tokens          β”‚   β”‚
β”‚  β”‚ β€’ Auto Settlement    β”‚  β”‚ β€’ Performance Tracking      β”‚   β”‚
β”‚  β”‚ β€’ Dispute System     β”‚  β”‚ β€’ Trust Scoring             β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      FRONTEND (Next.js)                         β”‚
β”‚  β€’ Worker Dashboard  β€’ Task Marketplace  β€’ Analytics           β”‚
β”‚  β€’ Wallet Integration (Circle)  β€’ Real-time Updates            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Technology Stack

🎨 Frontend

  • Framework: Next.js 15.5
  • UI Library: React 19
  • Styling: Tailwind CSS + shadcn/ui
  • State: React Query
  • Wallet: Circle User-Controlled Wallets
  • Blockchain: Viem + Wagmi

βš™οΈ Backend

  • Runtime: Rust 1.70+
  • Framework: Axum + Tokio
  • Database: PostgreSQL (Supabase)
  • Caching: Redis
  • Queue: Background jobs
  • Monitoring: Structured logging

⛓️ Blockchain

  • Network: Arc Testnet (Chain ID: 5042002)
  • Smart Contracts: Solidity 0.8.20
  • Framework: Foundry
  • Token: USDC (Circle)
  • NFTs: Soulbound Reputation Tokens
  • RPC: https://rpc.testnet.arc.network

πŸ“ Project Structure

HumanGridAI/
β”‚
β”œβ”€β”€ 🎨 Frontend (Next.js + TypeScript)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/                    # Next.js 15 app router
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboard/          # Worker dashboard
β”‚   β”‚   β”‚   β”œβ”€β”€ tasks/              # Task marketplace
β”‚   β”‚   β”‚   └── api/                # API routes
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/                 # shadcn components
β”‚   β”‚   β”‚   β”œβ”€β”€ wallet/             # Circle wallet integration
β”‚   β”‚   β”‚   └── tasks/              # Task components
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ circleWalletSDK.ts # Circle SDK config
β”‚   β”‚   β”‚   └── supabase.ts        # Database client
β”‚   β”‚   └── hooks/                  # React hooks
β”‚   β”‚
β”‚   β”œβ”€β”€ public/                     # Static assets
β”‚   └── package.json
β”‚
β”œβ”€β”€ βš™οΈ Rust Service (Backend)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main.rs                 # Entry point
β”‚   β”‚   β”œβ”€β”€ api/                    # REST API routes
β”‚   β”‚   β”œβ”€β”€ verifier/               # Task verification logic
β”‚   β”‚   β”œβ”€β”€ fraud/                  # Fraud detection engine
β”‚   β”‚   β”œβ”€β”€ reputation/             # Reputation calculation
β”‚   β”‚   β”œβ”€β”€ blockchain/             # Smart contract integration
β”‚   β”‚   └── models/                 # Data models
β”‚   β”‚
β”‚   β”œβ”€β”€ Cargo.toml                  # Rust dependencies
β”‚   └── .env.example                # Environment template
β”‚
β”œβ”€β”€ ⛓️ Smart Contracts (Solidity)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ HumanGridEscrow.sol    # USDC escrow & settlement
β”‚   β”‚   β”œβ”€β”€ ReputationSBT.sol      # Soulbound reputation NFTs
β”‚   β”‚   └── interfaces/            # Contract interfaces
β”‚   β”‚
β”‚   β”œβ”€β”€ test/                       # Foundry tests
β”‚   β”œβ”€β”€ script/                     # Deployment scripts
β”‚   └── foundry.toml                # Foundry configuration
β”‚
β”œβ”€β”€ πŸ“š Database (Supabase)
β”‚   β”œβ”€β”€ supabase-schema.sql        # Main database schema
β”‚   β”œβ”€β”€ supabase-worker-wallets-schema.sql
β”‚   └── insert-demo-tasks.sql      # Seed data
β”‚
└── πŸ“– Documentation
    β”œβ”€β”€ ARCHITECTURE.md             # System design
    β”œβ”€β”€ PHASE1_COMPLETE.md          # Smart contract docs
    β”œβ”€β”€ PHASE2_COMPLETE.md          # Rust service docs
    └── ARC_NETWORK_MIGRATION.md    # Arc testnet guide

πŸš€ Quick Start

Prerequisites

Before you begin, ensure you have the following installed:

1️⃣ Clone the Repository

git clone https://github.com/yourusername/HumanGridAI.git
cd HumanGridAI

2️⃣ Deploy Smart Contracts

# Navigate to contracts directory
cd contracts

# Install dependencies
forge install

# Run tests
forge test -vvv

# Deploy to Arc Testnet
forge script script/Deploy.s.sol \
  --rpc-url https://rpc.testnet.arc.network \
  --broadcast \
  --verify

# Save the deployed contract addresses
# You'll need them for the Rust service
πŸ“ Click to see expected output
βœ… HumanGridEscrow deployed at: 0x7Ff1781e128328e17ECaAA3E095192E2c5419454
   Explorer: https://testnet.arcscan.app/address/0x7Ff1781e128328e17ECaAA3E095192E2c5419454

βœ… ReputationSBT deployed at: 0xafB025Bf2c44E26Ce20132304948430d7978ebb7
   Explorer: https://testnet.arcscan.app/address/0xafB025Bf2c44E26Ce20132304948430d7978ebb7

βœ… Network: Arc Testnet (Chain ID: 5042002)
βœ… Current Block: 23,223,365+
βœ… Verification successful

3️⃣ Configure Rust Service

cd ../rust-service

# Copy environment template
cp .env.example .env

# Edit .env with your values
nano .env

Required environment variables:

# Database
DATABASE_URL=postgresql://user:pass@localhost/humangrid
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your-anon-key

# Blockchain (Arc Testnet)
ESCROW_CONTRACT_ADDRESS=0x7Ff1781e128328e17ECaAA3E095192E2c5419454
REPUTATION_CONTRACT_ADDRESS=0xafB025Bf2c44E26Ce20132304948430d7978ebb7
ARC_TESTNET_RPC_URL=https://rpc.testnet.arc.network
CHAIN_ID=5042002
PRIVATE_KEY=your-private-key

# Circle API
CIRCLE_API_KEY=your-circle-api-key
CIRCLE_APP_ID=your-app-id

# Server
SERVER_HOST=0.0.0.0
SERVER_PORT=8081

4️⃣ Start Rust Service

# Build the service
cargo build --release

# Run database migrations
sqlx migrate run

# Start the server
cargo run --release

The service will start on http://localhost:8081

βœ… Service Status:

  • Rust Backend: Running on http://localhost:8081
  • Connected to Arc Testnet (Chain ID: 5042002)
  • Features: Fraud detection, reputation minting enabled
  • Current Block Height: 23,223,365+

5️⃣ Setup Database

# Connect to your Supabase dashboard
# Navigate to SQL Editor
# Run these schema files in order:

1. supabase-schema.sql
2. supabase-worker-wallets-schema.sql
3. insert-demo-tasks.sql (optional, for testing)

6️⃣ Launch Frontend

cd ../ # Back to root directory

# Install dependencies
npm install

# Copy environment file
cp .env.example .env.local

# Edit .env.local
nano .env.local

Frontend environment variables:

NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
NEXT_PUBLIC_API_URL=http://localhost:8081
NEXT_PUBLIC_CIRCLE_APP_ID=your-circle-app-id
# Start development server
npm run dev

Visit http://localhost:3000 πŸŽ‰


πŸ“– Documentation

Comprehensive documentation is available in the following files:

Document Description
ARCHITECTURE.md Complete system design, protocol phases, and technical strategy
PHASE1_COMPLETE.md Smart contract implementation (Escrow + Reputation SBTs)
PHASE2_COMPLETE.md Rust verification service (Task validation + Fraud detection)
ARC_NETWORK_MIGRATION.md Guide to deploying on Arc Testnet
contracts/README.md Smart contract API reference
rust-service/README.md Backend API documentation

πŸ”Œ API Reference

Rust Backend Endpoints

Submit Task (AI Agent)

POST /api/tasks
Content-Type: application/json

{
  "task_type": "captcha_solve",
  "payload": {
    "image_url": "https://example.com/captcha.png"
  },
  "reward_usdc": "5.00",
  "deadline_seconds": 300
}

Get Task (Worker)

GET /api/workers/tasks/available
Authorization: Bearer <worker_token>

Submit Solution (Worker)

POST /api/workers/tasks/{task_id}/submit
Content-Type: application/json

{
  "solution": "ABC123",
  "time_taken": 45
}

View Full API Documentation β†’


πŸ§ͺ Testing

Smart Contracts

cd contracts

# Run all tests
forge test

# Run with verbosity
forge test -vvv

# Run specific test
forge test --match-test testEscrowDeposit

# Generate coverage report
forge coverage

Rust Service

cd rust-service

# Run unit tests
cargo test

# Run with output
cargo test -- --nocapture

# Run integration tests
cargo test --test integration_tests

Frontend

# Run unit tests
npm test

# Run E2E tests
npm run test:e2e

# Run with UI
npm run test:ui

πŸ› οΈ Development Workflow

Using Lovable (Recommended)

  1. Visit the Lovable Project
  2. Start prompting to make changes
  3. Changes are automatically committed to this repo

Using Your IDE

# Clone the repository
git clone <YOUR_GIT_URL>
cd HumanGridAI

# Install dependencies
npm install

# Start development server
npm run dev

# Make your changes and commit
git add .
git commit -m "feat: your feature description"
git push origin main

Using GitHub Codespaces

  1. Click the Code button on the repository
  2. Select Codespaces tab
  3. Click New codespace
  4. Edit files directly in the browser
  5. Commit and push changes

🚒 Deployment

Frontend Deployment

Option 1: Lovable (One-Click)

  1. Open your Lovable Project
  2. Click Share β†’ Publish
  3. Your app is now live! πŸŽ‰

Option 2: Vercel

npm install -g vercel
vercel deploy --prod

Option 3: Manual (any host)

npm run build
npm run start

Rust Service Deployment

# Build optimized binary
cargo build --release

# Deploy to your server (example with PM2)
pm2 start target/release/rust-service --name humangrid-api
pm2 save
pm2 startup

Smart Contracts

# Deploy to Arc Testnet (Current Deployment)
forge script script/Deploy.s.sol \
  --rpc-url https://rpc.testnet.arc.network \
  --broadcast \
  --verify

# Deployed Contracts:
# Escrow: 0x7Ff1781e128328e17ECaAA3E095192E2c5419454
# Reputation: 0xafB025Bf2c44E26Ce20132304948430d7978ebb7
# Explorer: https://testnet.arcscan.app/

🀝 Contributing

We welcome contributions from the community! Here's how to get started:

Contribution Guidelines

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'feat: add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Code Standards

  • Frontend: Follow ESLint rules, use TypeScript
  • Rust: Run cargo fmt and cargo clippy before committing
  • Solidity: Follow Solidity style guide, add NatSpec comments
  • Tests: Maintain >80% code coverage
  • Documentation: Update README if adding features

πŸ› Troubleshooting

Dev server not starting
# Clear Next.js cache
rm -rf .next

# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install

# Restart dev server
npm run dev
Rust compilation errors
# Update Rust toolchain
rustup update

# Clean build artifacts
cargo clean

# Rebuild
cargo build --release
Smart contract deployment fails
# Check RPC connection (Arc Testnet)
curl -X POST https://rpc.testnet.arc.network \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

# Verify you have testnet ETH on Arc
cast balance $YOUR_ADDRESS --rpc-url https://rpc.testnet.arc.network

# View deployed contracts
# Escrow: https://testnet.arcscan.app/address/0x7Ff1781e128328e17ECaAA3E095192E2c5419454
# Reputation: https://testnet.arcscan.app/address/0xafB025Bf2c44E26Ce20132304948430d7978ebb7

# Try deployment with more gas
forge script script/Deploy.s.sol --gas-limit 3000000

πŸ“Š Performance Benchmarks

Metric Value Network
Task Submission <500ms API Response Time
Verification <2s Off-chain Validation
Settlement <15s Arc Testnet Finality
Gas Cost ~$0.001 Per Transaction (Arc Testnet)
Throughput 1000 TPS Theoretical Max
Current Block 23,223,365+ Arc Testnet

πŸ” Security

  • Smart Contracts: Audited by [Auditor Name] (pending)
  • Access Control: Role-based permissions (RBAC)
  • Fraud Detection: Multi-layer verification system
  • Data Encryption: All sensitive data encrypted at rest
  • Rate Limiting: API endpoints protected against abuse

Report security issues: security@humangrid.ai


πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Circle for User-Controlled Wallets SDK
  • Base for low-cost L2 infrastructure
  • Foundry for smart contract development
  • Supabase for database and auth
  • shadcn/ui for beautiful components

πŸ”— Links


Built with ❀️ for the autonomous AI economy

⭐ Star this repo β€’ πŸ› Report Bug β€’ πŸ’‘ Request Feature

About

HumanGridAI - Decentralized marketplace connecting AI agents with human workers for verification tasks. Features trustless USDC payments on Base L2, fraud prevention, and reputation tracking.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors