Skip to main content

Overview

MetaVault AI consists of three main components that need to run together:
  1. Smart Contracts - Local blockchain node with deployed contracts
  2. AI Agents - Backend server managing vault strategies
  3. 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.

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.
Keep this terminal window open. The blockchain will reset if you stop the process.
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
Save the deployed addresses - you’ll need them for the next step.
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 (packages/agents/defi-portfolio/.env):
For Frontend (packages/frontend/.env.local):
You can automate this by creating a deployment script that outputs a .env file or use the addresses from the console output.
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:
  1. 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
  2. Import a test account using one of the private keys from the Hardhat node output
  3. Connect MetaMask to the frontend at http://localhost:3000
Only use test accounts from Hardhat for development. Never use accounts that hold real funds.

Available Scripts

Here are all the npm scripts available for development:

Root Package Scripts

Package-Specific Scripts

Navigate to packages/contracts and run:

Running AI Agent Automation

The AI agents can run automated tasks on a schedule:
This starts the Strategy Sentinel Agent to:
  • 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:
  1. Hardhat node
  2. AI agent server
  3. Frontend
  4. (Optional) Automation cron
2

Deploy Contracts

Deploy or redeploy contracts as needed:
3

Make Changes

Edit code in any package:
  • Contracts: Update .sol files, recompile with pnpm 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

Make sure:
  • Hardhat node is running
  • You’re using the correct network (--network localhost)
  • Your .env has a valid private key
Try restarting the Hardhat node:
Verify:
  • Contract addresses in .env match deployed addresses
  • RPC_URL points to http://127.0.0.1:8545
  • Hardhat node is running
Check agent logs for connection errors.
Ensure:
  • MetaMask is connected to Localhost 8545 network (Chain ID: 31337)
  • Contract addresses in .env.local are correct and prefixed with NEXT_PUBLIC_
  • You’ve refreshed the browser after updating .env.local
Find and kill the process using the port:
Or change the port in your configuration files.
If you restart the Hardhat node, all state is lost. You need to:
  1. Redeploy contracts
  2. Update environment variables
  3. Restart agents and frontend
  4. 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 logs

Watch 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