This directory contains sandboxes for testing, diagnosing, and simulating various components of the Web3AI project with full transparency. Each sandbox provides isolated environments for validating functionality and understanding system behavior.
Fastest way to get started:
cd sandboxes
./quickstart.shThe quickstart script will help you:
- Set up backend sandboxes with virtual environment
- Install dependencies and run tests
- Configure frontend sandbox pages
- Run contract compilation and tests
sandboxes/
βββ backend/ # Backend diagnostics and simulations
β βββ ai_diagnostics.py # AI model testing and validation
β βββ blockchain_simulation.py # Blockchain interaction testing
βββ frontend/ # Frontend component sandboxes
β βββ Web3Sandbox.tsx # Web3 wallet connection testing
β βββ AIChatSimulation.tsx # AI chat interface simulation
βββ contracts/ # Smart contract testing sandboxes
β βββ SimpleStorage.sol # Simple storage contract for testing
β βββ SimpleStorage.test.js # Contract test suite
β βββ deploy_sandbox.js # Deployment script with diagnostics
βββ quickstart.sh # Quick start automation script
βββ README.md # This file
These sandboxes provide:
- Transparency: Clear visibility into how each component functions
- Diagnostics: Tools to identify and troubleshoot issues
- Simulations: Safe environments to test interactions without affecting production
- Validation: Verify configurations and integrations are working correctly
Test and validate AI model integration with transparent output.
Features:
- Configuration validation
- API key verification
- Model connection testing
- Custom prompt testing
Usage:
# Navigate to project root
cd /path/to/Web3AI
# Activate backend virtual environment
source backend/venv/bin/activate # On Windows: backend\venv\Scripts\activate
# Run diagnostics
python sandboxes/backend/ai_diagnostics.py
# Test with custom prompt
python sandboxes/backend/ai_diagnostics.py --prompt "Explain smart contracts"Output Example:
π¬ Running AI Diagnostics Sandbox π¬
This sandbox provides transparency into AI model behavior
============================================================
AI Model Diagnostics
============================================================
β Configuration loaded successfully
Model: GPT-5.1-Codex-Max
API Key configured: True
============================================================
AI Prompt Test
============================================================
Prompt: Explain blockchain in one sentence
Response:
------------------------------------------------------------
Blockchain is a decentralized, distributed ledger technology...
------------------------------------------------------------
β AI model responded successfully
Simulate and test blockchain interactions with transparent reporting.
Features:
- RPC connection validation
- Network information retrieval
- Balance checking
- Transaction simulation
Usage:
# Run full simulation
python sandboxes/backend/blockchain_simulation.py
# Check specific address balance
python sandboxes/backend/blockchain_simulation.py --address 0x742d35Cc6634C0532925a3b844Bc454e4438f44eOutput Example:
βοΈ Running Blockchain Simulation Sandbox βοΈ
This sandbox provides transparency into blockchain interactions
============================================================
Blockchain RPC Connection Test
============================================================
β Configuration loaded
Network: mainnet
RPC URL: https://eth.llamarpc.com
β Connected to blockchain
============================================================
Network Information
============================================================
Chain ID: 1
Latest Block: 18500000
Current Gas Price: 25.5 Gwei
Interactive component for testing Web3 wallet connections.
Features:
- Wallet connection testing
- Address and balance display
- Network detection
- Connection diagnostics
Usage:
# Navigate to frontend directory
cd frontend
# Copy the sandbox to a page (example)
# Option 1: Create a new sandbox page
mkdir -p app/sandbox
cp ../sandboxes/frontend/Web3Sandbox.tsx app/sandbox/page.tsx
# Option 2: Import in existing page
# Add to your page.tsx:
# import Web3Sandbox from '@/sandboxes/frontend/Web3Sandbox'Then visit http://localhost:3000/sandbox in your browser.
What it tests:
- Web3 provider detection (MetaMask, etc.)
- Wallet connection flow
- Account address retrieval
- Balance checking
- Network/Chain ID detection
Interactive chat interface for testing AI backend integration.
Features:
- Backend API connectivity testing
- Message sending/receiving
- Error handling
- API status checking
Usage:
# Same setup as Web3Sandbox
# Create a page or import the component
# Make sure backend is running
cd backend
source venv/bin/activate
uvicorn app.main:app --reloadWhat it tests:
- Backend API availability
- Request/response flow
- Error handling
- Message history management
A simple storage contract designed for testing and validation.
Features:
- Basic storage operations (set, get)
- Increment/decrement functions
- Event emission
- Access control demonstration
Test Suite (contracts/SimpleStorage.test.js)
Comprehensive tests including:
- Deployment diagnostics
- Storage operations
- Multi-user simulations
- Gas usage diagnostics
Usage:
# Navigate to contracts directory
cd contracts
# Copy sandbox files to contracts directory
cp ../sandboxes/contracts/SimpleStorage.sol contracts/
cp ../sandboxes/contracts/SimpleStorage.test.js test/
# Run tests
npm test test/SimpleStorage.test.js
# Deploy to local network
npm run node # In one terminal
npm run deploy # In another terminal, or use deploy_sandbox.jsTransparent deployment with detailed diagnostics.
Usage:
# Copy deployment script
cp ../sandboxes/contracts/deploy_sandbox.js scripts/
# Deploy with diagnostics
npx hardhat run scripts/deploy_sandbox.js --network localhost
# Or use with other networks
npx hardhat run scripts/deploy_sandbox.js --network sepoliaOutput includes:
- Deployer account information
- Network details
- Contract address
- Test transactions with gas usage
- Verification steps
# From project root
cd backend
source venv/bin/activate
pip install -r requirements.txt
# Set up environment
cp .env.example .env
# Edit .env with your API keys
# Run diagnostics
cd ..
python sandboxes/backend/ai_diagnostics.py
python sandboxes/backend/blockchain_simulation.py# From project root
cd frontend
npm install
# Create sandbox page
mkdir -p app/sandbox/web3 app/sandbox/ai
echo "export { default } from '@/../sandboxes/frontend/Web3Sandbox';" > app/sandbox/web3/page.tsx
echo "export { default } from '@/../sandboxes/frontend/AIChatSimulation';" > app/sandbox/ai/page.tsx
# Start development server
npm run dev
# Visit http://localhost:3000/sandbox/web3
# Visit http://localhost:3000/sandbox/ai# From project root
cd contracts
npm install
# Copy sandbox files
cp ../sandboxes/contracts/SimpleStorage.sol contracts/
cp ../sandboxes/contracts/SimpleStorage.test.js test/
# Run tests
npm test test/SimpleStorage.test.js
# Start local node and deploy
npm run node # Terminal 1
npx hardhat run scripts/deploy_sandbox.js --network localhost # Terminal 2Each sandbox provides transparent diagnostic information:
- β Configuration validation
- β API connectivity
- β Model availability
- β Response generation
- β RPC connection status
- β Network information
- β Balance queries
- β Transaction simulation
- β Provider detection
- β Wallet connection
- β Network identification
- β Account information
- β Deployment success
- β Function execution
- β Event emission
- β Gas usage metrics
Problem: AI diagnostics fail Solution:
- Check
.envfile has validOPENAI_API_KEY - Verify model name is correct
- Ensure internet connectivity
Problem: Blockchain simulation fails Solution:
- Check
ETH_RPC_URLin.env - Try alternative RPC endpoint
- Verify network configuration
Problem: Web3 Sandbox shows no provider Solution:
- Install MetaMask or another Web3 wallet
- Check browser extensions
- Reload the page
Problem: AI Chat Simulation can't connect Solution:
- Ensure backend is running (
uvicorn app.main:app --reload) - Check
NEXT_PUBLIC_API_URLin.env.local - Verify CORS settings
Problem: Tests fail Solution:
- Run
npm run compilefirst - Check Hardhat configuration
- Ensure correct Solidity version
Problem: Deployment fails Solution:
- Check network configuration in
hardhat.config.js - Verify account has sufficient balance
- Ensure correct RPC URL
- Always run diagnostics before deploying to production
- Use sandboxes to test new features in isolation
- Check outputs for transparency in behavior
- Document findings from sandbox testing
- Keep sandboxes updated with main codebase changes
- Sandboxes use test data and configurations
- Never commit real API keys or private keys
- Use testnets for blockchain simulations
- Frontend sandboxes are safe for production builds (client-side only)
- FastAPI Documentation
- Web3.py Documentation
- Hardhat Documentation
- Next.js Documentation
- Ethereum Development
When adding new sandboxes:
- Follow the existing structure
- Include comprehensive documentation
- Add diagnostic output
- Provide clear usage examples
- Test thoroughly before committing
ISC - Same as the main project