Overview
MetaVault AI consists of three main components that need to run together:- Smart Contracts - Local blockchain node with deployed contracts
- AI Agents - Backend server managing vault strategies
- Frontend - Web interface for users
Make sure you’ve completed the Local Setup guide before proceeding.
Quick Start
You can run all components at once or start them individually.- Run All (Recommended)
- Run Individually
From the root directory, start all services simultaneously:This command uses
concurrently to run:- Local Hardhat node on port 8545
- AI Agent server on port 3001
- Frontend development server on port 3000
Step-by-Step Setup
For first-time setup, follow these steps in order:1
Start Local Blockchain
Open a terminal and start the Hardhat local node:The node will start on
http://127.0.0.1:8545 and display 20 test accounts with private keys.Expected Output:2
Deploy Smart Contracts
Open a new terminal and deploy the contracts to your local node:This script will deploy:
- Mock LINK token
- Mock WETH token
- Mock Aave Pool
- Mock Swap Router
- MetaVault contract
- Aave V3 Strategy
- Leverage Strategy
The deployment script deploys mock versions of Aave and Uniswap for testing purposes. These simulate the behavior of real DeFi protocols.
3
Update Environment Variables
Copy the deployed contract addresses and update your environment files:For AI Agents (For Frontend (
packages/agents/defi-portfolio/.env):packages/frontend/.env.local):4
Start AI Agent Server
Open a new terminal and start the AI agent server:The server will start on the port specified in your
.env file (default: 3001).Expected Output:The agents will automatically connect to your local blockchain and start monitoring the vault.
5
Start Frontend Development Server
Open a new terminal and start the Next.js frontend:The frontend will be available at
http://localhost:3000.Expected Output:6
Configure MetaMask
To interact with your local blockchain through the frontend:
-
Open MetaMask and add a custom network:
- Network Name:
Localhost 8545 - RPC URL:
http://127.0.0.1:8545 - Chain ID:
31337 - Currency Symbol:
ETH
- Network Name:
- Import a test account using one of the private keys from the Hardhat node output
-
Connect MetaMask to the frontend at
http://localhost:3000
Available Scripts
Here are all the npm scripts available for development:Root Package Scripts
Package-Specific Scripts
- Contracts
- Agents
- Frontend
Navigate to
packages/contracts and run:Running AI Agent Automation
The AI agents can run automated tasks on a schedule:- Monitor strategy health every 5 minutes
- Check LTV ratios and liquidation risks
- Automatically rebalance portfolios
- Harvest and compound yields
The automation is optional for development but recommended to see the full AI agent capabilities.
Development Workflow
Here’s a typical development workflow:1
Start Services
Open 3-4 terminal windows and start:
- Hardhat node
- AI agent server
- Frontend
- (Optional) Automation cron
2
Deploy Contracts
Deploy or redeploy contracts as needed:
3
Make Changes
Edit code in any package:
- Contracts: Update
.solfiles, recompile withpnpm hardhat compile - Agents: TypeScript changes auto-reload with
tsx watch - Frontend: Next.js hot-reloads automatically
4
Test Changes
- Interact through frontend at
http://localhost:3000 - Call agent API directly at
http://localhost:3001 - Use Hardhat console for contract interactions
Accessing the Application
Once everything is running:Frontend
URL: http://localhost:3000Main user interface for depositing, withdrawing, and chatting with AI
Agent API
URL: http://localhost:3001AI agent REST API endpoints
Chat Agent
URL: http://localhost:3002Chat interface endpoint
Common Issues
Contracts not deploying
Contracts not deploying
Make sure:
- Hardhat node is running
- You’re using the correct network (
--network localhost) - Your
.envhas a valid private key
Agents can't connect to contracts
Agents can't connect to contracts
Verify:
- Contract addresses in
.envmatch deployed addresses - RPC_URL points to
http://127.0.0.1:8545 - Hardhat node is running
Frontend shows wrong network
Frontend shows wrong network
Ensure:
- MetaMask is connected to
Localhost 8545network (Chain ID: 31337) - Contract addresses in
.env.localare correct and prefixed withNEXT_PUBLIC_ - You’ve refreshed the browser after updating
.env.local
Port already in use
Port already in use
Find and kill the process using the port:Or change the port in your configuration files.
Blockchain state reset
Blockchain state reset
If you restart the Hardhat node, all state is lost. You need to:
- Redeploy contracts
- Update environment variables
- Restart agents and frontend
- Reconfigure MetaMask (import accounts again)
Development Tips
Use Hardhat Console
Interact with contracts directly:
Enable Debug Logs
Set
ADK_DEBUG="true" in agents .env for detailed agent logsWatch Contract Changes
Auto-recompile on changes:
Use Hardhat Network Helper
Time travel and snapshot in tests:
Next Steps
Testing Guide
Learn how to run tests and verify functionality
Architecture
Understand the system architecture