Built for ETHIndia Villa 2025
Save for your goals with AI-optimized investment strategies. Tell our AI what you're saving for, and it automatically consults expert AI advisors - paying them directly via blockchain - to create your personalized DeFi investment plan.
Powered by x402: Your AI agent autonomously purchases expert financial strategies using crypto micropayments. No subscriptions, no API keys, just instant pay-per-use AI services.
Traditional approach:
- Subscribe to investment advisor ($99/month)
- Trust centralized recommendations
- Manual portfolio management
Our approach:
- ๐ฌ Chat: "I want to save 0.12 ETH for a car in 12 months"
- ๐ค AI calculates your monthly investment (0.01 ETH)
- ๐ธ AI pays Expert AI 0.001 USDC via x402 for strategy
- โ Funds automatically allocated to Aave, Compound, Uniswap
- ๐ Everything verifiable on-chain
The x402 Magic: Your Protocol AI doesn't need your permission to consult experts. It simply pays for the service it needs (0.001 USDC per strategy) and gets back professional investment advice instantly. This is the future of AI services - autonomous, pay-per-use, decentralized.
- You: "I want to save for a toy worth 0.12 ETH in 12 months with low risk"
- Protocol AI: Calculates you need 0.01 ETH/month, pays Expert AI for strategy
- Expert AI: Analyzes and returns: 50% Aave, 50% Compound, 0% Uniswap (low risk)
- You: Approve the 0.01 ETH deposit
- Smart Contract: Automatically distributes across DeFi protocols
- Result: Your investment is working, optimized by AI, all on-chain
Behind the scenes: AI agents are discovering services, negotiating prices, and transacting value - all enabled by x402's payment protocol.
USER
โ (wants to save 0.12 ETH)
โ
PROTOCOL AI AGENT (Free)
โ (calculates: 0.01 ETH/month)
โ
โโโ EXPERT AI AGENT (x402 Payment: 0.001 USDC) ๐ฐ
โ โโ Analyzes: amount, timeline, risk tolerance
โ โโ Returns: DeFi allocation strategy
โ
SMART CONTRACT (SIPProtocol.sol)
โ (receives 0.01 ETH, stores plan)
โ
โโโ MockAave (50% = 0.005 ETH)
โโโ MockCompound (50% = 0.005 ETH)
โโโ MockUniswap (0% = 0.000 ETH)
Contracts Deployed
USER_ADDRESS=0xDBA0c4FC9C9c215396852fcA118213092CEa5674
BUYER_ADDRESS=0x5000BCC077911724C7A880a78c17F768caB5b7a2
SELLER_ADDRESS=0xDEbf4BFD4575a55aa261a9eA6a32000d47E10a9A
SIP_PROTOCOL_ADDRESS=0xa718997243459453804a00bfd06F571820Bc85A5
MOCK_AAVE_ADDRESS=0x68839DB8a89434c2E16bD103BE0Aae6dddf24a90
MOCK_COMPOUND_ADDRESS=0x6Bb3A3d3df74E6B28F3ebd7341AA6C3b70306aAB
MOCK_UNISWAP_ADDRESS=0x7cDBf5C2657fF228FB494bc447b4BA8FFCD46293
Flow:
- Protocol AI Agent acts as buyer (pays Expert AI)
- Expert AI Agent acts as seller (receives payment via x402)
- Payment happens automatically using x402 protocol
- All transactions verifiable on Base Sepolia
- Solidity ^0.8.20
- Base Sepolia testnet
- Mock DeFi protocols (Aave, Compound, Uniswap)
- Node.js + Express
- OpenAI GPT-4 (Expert AI strategy generation)
- x402-express (seller/payment receiver)
- x402-axios (buyer/payment sender)
- x402 protocol for AI-to-AI payments
- USDC micropayments (0.001 USDC per strategy)
- ETH-based user investments
x402-ISP-AI/
โโโ contracts/ # Smart contracts
โ โโโ SIPProtocol.sol # Main SIP logic
โ โโโ MockAave.sol # Mock Aave
โ โโโ MockCompound.sol # Mock Compound
โ โโโ MockUniswap.sol # Mock Uniswap
โ
โโโ x402/ # AI Agents
โโโ 1-expert-agent.js # Expert AI (seller)
โโโ 2-interactive-demo.js # Protocol AI (buyer) - CLI demo
โโโ protocol-logic.js # Shared logic
โโโ protocol-agent.js # Automated version
- Node.js v18+
- Base Sepolia testnet access
- OpenAI API key
# Clone repo
git clone https://github.com/omsant02/x402-ISP-AI.git
cd x402-ISP-AI/x402
# Install dependencies
npm install
# Configure .env (see .env.example)
SELLER_ADDRESS=0x... # Expert AI receives payments here
BUYER_PRIVATE_KEY=0x... # Protocol AI pays from here
USER_PRIVATE_KEY=0x... # End user deposits from here
SIP_PROTOCOL_ADDRESS=0x... # Deployed SIP contract
MOCK_AAVE_ADDRESS=0x...
MOCK_COMPOUND_ADDRESS=0x...
MOCK_UNISWAP_ADDRESS=0x...
OPENAI_API_KEY=sk-...
RPC_URL=https://sepolia.base.org- User Wallet: 0.02 ETH (0.01 for SIP + gas)
- Buyer Wallet: 0.001 USDC (for Expert AI payment)
Get testnet funds: Alchemy Base Sepolia Faucet
node 1-expert-agent.jsExpected output:
๐ค Expert AI Agent: http://localhost:4021
๐ต Cost: 0.001 USDC per strategy
node 2-interactive-demo.jsFollow the prompts:
What would you like to save for? > toy
How much does it cost? (in ETH) > 0.12
In how many months? > 12
Risk tolerance? (low/moderate/high) > moderate
The system will:
- Calculate monthly deposit (0.01 ETH)
- Pay Expert AI 0.001 USDC via x402
- Receive strategy from Expert AI
- Execute first deposit on-chain
- Allocate funds to mock protocols
All transactions are real and verifiable on Base Sepolia Explorer.
1. Protocol AI calls Expert AI API
โ Gets HTTP 402 Payment Required
2. x402-axios (buyer side) intercepts 402
โ Creates payment proof
โ Signs with private key
โ Executes USDC transfer on-chain
3. Retries request with X-PAYMENT header
โ Contains cryptographic payment proof
4. x402-express (seller side) verifies
โ Checks signature validity
โ Confirms on-chain transaction via facilitator
โ Allows request through โ
5. Expert AI processes request
โ Returns investment strategy
Key Point: Payment happens automatically - no manual approvals needed in code. The x402 libraries handle the entire payment flow.
Traditional APIs require:
- API keys
- Subscription management
- Rate limiting
- Authentication infrastructure
With x402:
- โ Pay-per-use (true micropayments)
- โ No API keys needed
- โ No user accounts
- โ Perfect for AI agent economies
- โ Enables AI-to-AI commerce
- Automatic Payment: x402 libraries handle payment flow transparently
- On-Chain Verification: Every payment is a real blockchain transaction
- AI Adaptation: Expert AI adjusts strategy based on risk tolerance
- Smart Contract Integration: Seamless DeFi protocol interaction
Example successful transaction: View on BaseScan
What happened:
- User deposited 0.01 ETH
- Smart contract allocated:
- 50% โ MockAave (0.005 ETH)
- 50% โ MockCompound (0.005 ETH)
- 0% โ MockUniswap (low risk strategy)
- Chainlink Automation for monthly deposits
- Periodic rebalancing (Expert AI called every 3 days)
- Real Aave/Compound/Uniswap integration
- Multi-strategy support
- Frontend UI (currently CLI)
- Starknet implementation
Built by: Om Santoshwar , Ayush Ranjan , Thirumurugan Sivalingam , Adithya
Tracks:
- x402 Protocol Integration
- AI Agents
- DeFi Innovation
Sponsor Technologies:
- Base (deployment network)
- OpenAI (AI strategy generation)
- x402 (payment protocol)
MIT
Made with โค๏ธ for the future of autonomous AI economies