Skip to content

ChaosChain/erc-8004-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ERC-8004 Trustless Agents Example

A complete demonstration of the ERC-8004 Trustless Agents standard with AI Agents.

This example showcases how AI agents can interact trustlessly across organizational boundaries using the ERC-8004 registry system, demonstrating the future of decentralized AI collaboration.

🎯 What This Example Demonstrates

  • βœ… ERC-8004 Registry Contracts: Identity, Reputation, and Validation registries
  • βœ… AI Agents: Using CrewAI for sophisticated market analysis and validation
  • βœ… Trustless Interactions: Agents discover, validate, and provide feedback without pre-existing trust
  • βœ… Complete Audit Trail: Full blockchain-based accountability and transparency
  • βœ… Multi-Agent Workflows: Collaborative AI systems working together

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Server Agent  β”‚    β”‚ Validator Agent β”‚    β”‚  Client Agent   β”‚
β”‚    (Alice)      β”‚    β”‚     (Bob)       β”‚    β”‚   (Charlie)     β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ Market        β”‚    β”‚ β€’ Valdidation   β”‚    β”‚ β€’ Feedback      β”‚
β”‚   Analysis      β”‚                      β”‚    β”‚   Authorization β”‚
β”‚ β€’ Multi-agent   β”‚    β”‚ β€’ Quality       β”‚    β”‚ β€’ Reputation    β”‚
β”‚   workflows     β”‚    β”‚   Assessment    β”‚    β”‚   Management    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚  ERC-8004 Registriesβ”‚
                    β”‚                     β”‚
                    β”‚ β€’ Identity Registry β”‚
                    β”‚ β€’ Reputation Registryβ”‚
                    β”‚ β€’ Validation Registryβ”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  1. Python 3.8+ with pip
  2. Node.js 16+ with npm (for Foundry)
  3. Foundry (for smart contracts)

Installation

  1. Clone and setup the example:

    git clone https://github.com/chaoschain/erc-8004-example.git
    cd erc-8004-example
    
    # Option 1: Automated setup (recommended)
    ./setup.sh
    
    # Option 2: Manual setup
    pip install -r requirements.txt
    curl -L https://foundry.paradigm.xyz | bash
    foundryup
  2. Compile the smart contracts:

    cd contracts
    forge install
    forge build
    cd ..
  3. Configure environment:

    cp .env.example .env
    # Edit .env with your configuration
  4. Start a local blockchain (optional):

    # In a separate terminal
    anvil

Run the Demo

python demo.py

πŸ“‹ What Happens in the Demo

Step 1: Contract Deployment

  • Deploys the three ERC-8004 registry contracts
  • Creates a complete trustless infrastructure

Step 2: Agent Initialization

  • Alice (Server Agent): Market analysis service
  • Bob (Validator Agent): Analysis validation service
  • Charlie (Client Agent): Feedback and reputation management

Step 3: Agent Registration

  • All agents register with the Identity Registry
  • Receive unique on-chain identities and agent IDs

Step 4: Market Analysis Workflow

  • Alice performs comprehensive BTC market analysis
  • Multi-agent workflow with analyst and reviewer roles
  • Generates structured analysis with recommendations

Step 5: Validation Request

  • Alice submits her analysis for validation by Bob
  • Creates cryptographic hash of the work
  • Stores analysis data for validator access

Step 6: AI-Powered Validation

  • Bob validates Alice's analysis
  • Multi-agent validation with validator and QA specialist roles
  • Generates validation score and detailed feedback

Step 7: Validation Response

  • Bob submits validation score (0-100) on-chain
  • Creates permanent, immutable validation record

Step 8: Feedback Authorization

  • Charlie authorizes feedback for Alice's services
  • Enables reputation building and trust networks

Step 9: Audit Trail

  • Complete blockchain-based audit trail
  • Full transparency and accountability

πŸ€– AI Agent Details

Server Agent (Alice)

  • Role: Market Analysis Service Provider
  • Capabilities:
    • Senior Market Analyst for trend identification
    • Risk Assessment Specialist for validation
    • Structured analysis with confidence scores
    • Professional reporting standards

Validator Agent (Bob)

  • Role: Analysis Validation Service
  • Capabilities:
    • Senior Analysis Validator for methodology review
    • Quality Assurance Specialist for final assessment
    • Comprehensive scoring (0-100)
    • Detailed feedback and improvement recommendations

πŸ“ Project Structure

erc-8004-example/
β”œβ”€β”€ README.md                 # This file
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ .env.example             # Environment configuration template
β”œβ”€β”€ demo.py                  # Main demonstration script
β”œβ”€β”€ setup.sh                 # Automated setup script
β”œβ”€β”€ SUMMARY.md               # Project summary
β”œβ”€β”€ ERC-XXXX Trustless Agents v0.3.md  # ERC specification
β”‚
β”œβ”€β”€ contracts/               # Smart contracts
β”‚   β”œβ”€β”€ src/                # Contract source code
β”‚   β”‚   β”œβ”€β”€ IdentityRegistry.sol
β”‚   β”‚   β”œβ”€β”€ ReputationRegistry.sol
β”‚   β”‚   β”œβ”€β”€ ValidationRegistry.sol
β”‚   β”‚   └── interfaces/     # Contract interfaces
β”‚   β”œβ”€β”€ out/                # Compiled artifacts (ABIs)
β”‚   β”œβ”€β”€ script/             # Deployment scripts
β”‚   └── foundry.toml        # Foundry configuration
β”‚
β”œβ”€β”€ agents/                  # AI agent implementations
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ base_agent.py       # Base ERC-8004 agent class
β”‚   β”œβ”€β”€ server_agent.py     # Market analysis server agent
β”‚   └── validator_agent.py  # Analysis validation agent
β”‚
β”œβ”€β”€ scripts/                # Utility scripts
β”‚   └── deploy.py           # Contract deployment script
β”œβ”€β”€ data/                   # Generated analysis data (created at runtime)
└── validations/            # Generated validation data (created at runtime)

πŸ”§ Configuration

Environment Variables (.env)

# Blockchain Configuration
RPC_URL=http://127.0.0.1:8545        # Local Anvil
PRIVATE_KEY=0x0000000000000000000000000000000000000000000000000000000000000000
CHAIN_ID=31337

# Agent Domains (optional)
AGENT_DOMAIN_ALICE=alice.example.com
AGENT_DOMAIN_BOB=bob.example.com

# AI Configuration (optional - for enhanced AI features)
# The demo works without these, using fallback analysis
# OPENAI_API_KEY=your_openai_api_key_here
# ANTHROPIC_API_KEY=your_anthropic_api_key_here

Network Support

The example works with any EVM-compatible network:

  • Local Development: Anvil/Hardhat (default)
  • Testnets: Sepolia, Goerli, Base Sepolia
  • Mainnets: Ethereum, Base, Arbitrum, Optimism

Simply update the RPC_URL and CHAIN_ID in your .env file.

πŸŽ“ Learning Outcomes

After running this example, you'll understand:

  1. ERC-8004 Standard: How trustless agent interactions work
  2. Registry Architecture: Identity, reputation, and validation systems
  3. Blockchain Integration: Smart contract interaction patterns
  4. Trust Models: How agents build reputation without pre-existing relationships

πŸ” Key Features Demonstrated

Trust Models

  • Identity Registry: Sovereign, portable agent identities
  • Reputation Registry: Decentralized feedback and rating systems
  • Validation Registry: Cryptoeconomic validation mechanisms

AI Capabilities

  • Multi-Agent Workflows: Collaborative AI systems
  • Structured Analysis: Professional-grade market analysis
  • Quality Validation: AI-powered validation and scoring
  • Continuous Learning: Agents improve through feedback

Blockchain Integration

  • Smart Contract Interaction: Seamless Web3 integration
  • Event Monitoring: Real-time blockchain event handling
  • Gas Optimization: Efficient transaction patterns
  • Multi-Network Support: Works across EVM chains

πŸ› οΈ Extending the Example

Adding New Agent Types

  1. Create a new agent class inheriting from ERC8004BaseAgent
  2. Implement AI workflows for your specific use case
  3. Define trust models your agent supports
  4. Update the demo script to include your agent

Integrating with Real APIs

  1. Replace mock data in MarketAnalysisTool with real API calls
  2. Add authentication for external services
  3. Implement error handling for network failures
  4. Add rate limiting for API usage

Deploying to Production

  1. Use secure key management (not hardcoded private keys)
  2. Deploy to testnets first for validation
  3. Implement proper monitoring and logging
  4. Add comprehensive error handling

🀝 Contributing

This example is designed to be educational and extensible. Contributions are welcome:

  1. Bug fixes and improvements
  2. New agent types and use cases
  3. Additional trust models and validation methods
  4. Documentation and tutorials

πŸ“š Additional Resources

⚠️ Important Notes

  • Demo Purpose: This is an educational example, not production-ready code
  • Security: Use proper key management in production environments
  • Gas Costs: Monitor transaction costs on mainnet deployments
  • AI Functionality: Demo works fully without API keys using fallback analysis
    • With API keys: Full AI-powered analysis via CrewAI + LLMs
    • Without API keys: Intelligent fallback analysis (still demonstrates all ERC-8004 features)
  • Network Requirements: Requires a running blockchain (Anvil recommended for local testing)

πŸŽ‰ Success Metrics

When you run this example successfully, you'll see:

  • βœ… All contracts deployed and verified
  • βœ… Three agents registered with unique IDs (Alice: Server, Bob: Validator, Charlie: Client)
  • βœ… Complete market analysis generated by AI (BTC analysis with trend, support/resistance levels)
  • βœ… Professional validation with scoring (96-100/100 validation scores)
  • βœ… Full blockchain audit trail with transaction hashes
  • βœ… Trustless agent interactions demonstrated across 7 steps

Expected Output: The demo runs through all 7 steps, showing real multi-agent workflows performing market analysis and validation, even without external API keys (using intelligent fallback analysis).

This example proves that sophisticated AI agents can work together trustlessly, laying the foundation for a decentralized agent economy!


Built with ❀️ for the ERC-8004 Trustless Agents standard

About

ERC-8004 in action!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published