This project demonstrates two different approaches to meta-transactions with AI validation on Ethereum-compatible blockchains. It showcases both EIP-712 (direct signature validation) and EIP-2771 (forwarder-based) implementations, each with their unique advantages.
One-line setup for everything:
chmod +x setup.sh && ./setup.sh
This interactive script will guide you through setting up either or both implementations.
Diagram: High-level architecture showing the interaction between Client, AI Service, and Smart Contracts.
Direct signature validation approach:
- Simple & Efficient: Direct signature verification in contract
- Lower Gas Costs: Minimal overhead
- Basic AI Validation: Relayer with AI content checking
- Great for: Simple meta-transaction needs
Standard-compliant forwarder approach:
- Advanced AI Validation: Sophisticated content moderation using Ollama
- Standard Compliant: Full EIP-2771 implementation
- Highly Composable: Works with any ERC2771Context contract
- Rich Features: Significance scoring, validation controls, owner management
- Great for: Production systems requiring advanced validation
- Gasless Transactions: Users don't need ETH for gas fees
- AI Validation: Transactions validated by AI before execution
- Nonce Management: Prevents replay attacks
- Secure Signatures: EIP-712 structured data signing
- Ollama Integration: Local LLM for content moderation
- Significance Scoring: Automatic transaction importance assessment
- Advanced Controls: Owner/validator permissions, thresholds
- Standard Compliance: Full EIP-2771 forwarder pattern
new-ai-validator/
├── setup.sh # Main setup script
├── DIFFERENCE.md # Implementation comparison
├── EIP712/ # EIP-712 Implementation
│ ├── setup.sh # Automated setup for EIP-712
│ ├── contracts/
│ │ ├── src/EIPMetaTx.sol # Direct signature meta-tx contract
│ │ └── script/EIPMeta.s.sol # Deployment script
│ ├── client/signer.js # EIP-712 signing client
│ ├── relayer/
│ │ ├── index.js # Basic relayer service
│ │ └── ollama-relayer.js # AI validation relayer
│ └── README.md # EIP-712 documentation
├── EIP2771/ # EIP-2771 Implementation
│ ├── setup.sh # Automated setup for EIP-2771
│ ├── src/
│ │ ├── AIValidatedForwarder.sol # AI-powered forwarder
│ │ └── MetaTxInteractionRecipient.sol # Recipient contract
│ ├── ollama-ai-service.js # AI validation service
│ ├── client/signer.js # EIP-2771 client
│ └── README.md # EIP-2771 documentation
├── client/ # Legacy EIP-712 Client
│ └── README.md # Legacy client documentation
└── relayer/ # Legacy EIP-712 Relayer
└── README.md # Legacy relayer documentation
Before running the setup scripts, ensure you have:
- Node.js (v18 or higher) - Download here
- Foundry (latest version) - Installation guide
- Ollama (for AI validation) - Download here
Run the main setup script and choose your implementation:
./setup.sh
This will guide you through:
- Choosing between EIP-712 and EIP-2771 (or both)
- Installing all dependencies
- Deploying contracts to your chosen network
- Configuring all services
- Providing next steps to run the system
cd EIP712/
./setup.sh
cd EIP2771/
./setup.sh
Both setup scripts accept environment variables for configuration:
# Network configuration
export RPC_URL="http://localhost:9650/ext/bc/HekfYrK1fxgzkBSPj5XwBUNfxvZuMS7wLq7p7r6bQQJm6jA2M/rpc"
export CHAIN_ID="930393"
export PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
# AI configuration
export OLLAMA_MODEL="llama3.2:latest"
# Run setup with custom configuration
./setup.sh
After setup, follow these steps based on your chosen implementation:
# Terminal 1: Start the relayer
cd EIP712/relayer/
node ollama-relayer.js
# Terminal 2: Run the client
cd EIP712/client/
node signer.js
# Terminal 1: Start the AI service
cd EIP2771/
node ollama-ai-service.js
# Terminal 2: Run the client
cd EIP2771/client/
node signer.js
- Client Signs: Creates EIP-712 signature for meta-transaction
- Relayer Validates: Basic AI validation and submits to contract
- Contract Executes: Verifies signature and executes transaction
- Client Signs: Creates EIP-2771 compliant meta-transaction
- AI Service Validates: Advanced validation using Ollama LLM
- Forwarder Submits: AI-validated forwarder submits to recipient
- Recipient Executes: ERC2771Context recipient executes transaction
- Simple content filtering
- Basic approval/rejection logic
- Lightweight validation
- Ollama Integration: Local LLM analysis
- Content Moderation: Sophisticated language understanding
- Significance Scoring: Automatic importance assessment
- Threshold Controls: Configurable validation levels
- Owner Controls: Admin override capabilities
Verify all services are running:
# Ollama API
curl http://localhost:11434/api/tags
# EIP-712 Relayer
curl http://localhost:3000/health
# EIP-2771 AI Service
curl http://localhost:3001/health
# Blockchain RPC
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}' \
http://localhost:9650/ext/bc/HekfYrK1fxgzkBSPj5XwBUNfxvZuMS7wLq7p7r6bQQJm6jA2M/rpc
# EIP-712 tests
cd EIP712/contracts/
forge test -v
# EIP-2771 tests
cd EIP2771/
forge test -v
Both implementations support various interaction types:
// Social media interactions
"liked_post_123"
"comment_on_post_456"
"shared_article_789"
// E-commerce interactions
"purchased_item_abc"
"reviewed_product_xyz"
"added_to_wishlist_def"
The EIP-2771 implementation provides detailed AI analysis of interaction content and intent.
-
"Invalid signature" error:
- Check that the user private key matches the address
- Verify the EIP-712 domain parameters match between client and contract
-
"Contract not found" error:
# Check prerequisites
node --version # Should be v18+
forge --version # Should be latest
ollama --version # Should be installed
# Re-run with verbose output
bash -x ./setup.sh
# Check blockchain connectivity
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}' \
$RPC_URL
# Verify account has funds
cast balance $DEPLOYER_ADDRESS --rpc-url $RPC_URL
# Check Ollama status
curl http://localhost:11434/api/tags
# Restart Ollama if needed
ollama serve
# Pull required model
ollama pull llama3.2:latest
- EIP-712: Check domain parameters match between client and contract
- EIP-2771: Verify forwarder address is trusted by recipient
- EIP-712: Basic filter - try "liked_post" or "comment_here"
- EIP-2771: AI analysis - use meaningful, appropriate content
# Check contract addresses
cat EIP712/contracts/.contract_address # EIP-712
cat EIP2771/.forwarder_address # EIP-2771 forwarder
cat EIP2771/.recipient_address # EIP-2771 recipient
# View recent transactions
cast logs --from-block latest --address $CONTRACT_ADDRESS --rpc-url $RPC_URL
# Check user nonces
cast call $CONTRACT_ADDRESS "nonces(address)(uint256)" $USER_ADDRESS --rpc-url $RPC_URL
Feature | EIP-712 | EIP-2771 |
---|---|---|
Setup Complexity | Simple | Moderate |
Gas Costs | Lower | Higher |
AI Validation | Basic filtering | Advanced LLM analysis |
Standard Compliance | Custom | EIP-2771 compliant |
Composability | Limited | High |
Production Ready | Demo | Near-production |
For detailed comparison, see DIFFERENCE.md
.
- EIP-712 Guide: Detailed EIP-712 setup and usage
- EIP-2771 Guide: Comprehensive EIP-2771 documentation
- Implementation Comparison: Side-by-side feature comparison
- Legacy Client Documentation: Legacy EIP-712 client
- Legacy Relayer Documentation: Legacy EIP-712 relayer
- Enhanced AI Models: Integrate GPT-4, Claude, or specialized content models
- Rate Limiting: Implement proper DoS protection
- Monitoring: Add comprehensive logging and metrics
- Error Handling: Improve error messages and recovery
- Web Interface: Build React/Vue frontend
- Wallet Integration: Support MetaMask, WalletConnect
- Multi-chain: Deploy to Polygon, Arbitrum, Optimism
- Analytics: Transaction volume, validation rates, user patterns
- Batch Transactions: Process multiple meta-transactions
- Dynamic Pricing: AI-based gas price optimization
- Machine Learning: Adaptive validation thresholds
- Cross-chain: Enable meta-transactions across networks
Important: This is a demonstration project. For production use:
- Key Management: Use secure key storage (HSM, KMS)
- Private Networks: Don't expose private keys in code
- Rate Limiting: Implement comprehensive DoS protection
- Security Audits: Conduct thorough smart contract audits
- Monitoring: Add real-time security monitoring
- Access Controls: Implement proper authentication/authorization
Contributions welcome! Areas of interest:
- AI model improvements and new providers
- Gas optimization techniques
- Security enhancements
- Documentation improvements
- Frontend implementations
- Testing and QA
MIT License - see LICENSE for details.
Happy meta-transacting!
Built with love for the Ethereum community