☐ Replace mock contract interactions with real functionality
☐ Update UI components with futuristic design
☐ Implement real-time data hooks
☐ Test all functionality with real contracts
4.9 KiB
4.9 KiB
Contract Integration Guide
Overview
This guide explains how the smart contracts are integrated with the frontend application.
Smart Contracts
1. VaultManager Contract
- Address:
0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9 - Functions:
deposit(amount)- Deposit ETH into vaultwithdraw(amount)- Withdraw ETH from vaultgetTotalBalance()- Get total vault balancegetUserBalance()- Get user's vault balance
2. StableVault Contract
- Address:
0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9 - Functions:
deposit(amount)- Internal deposit functionwithdraw(amount)- Internal withdraw functiongetTotalBalance()- Get total balance
3. RewardNFT Contract
- Address:
0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 - Functions:
mintGenesis(to)- Mint Genesis NFT (+2.5% APY boost)mintMultiplier(to)- Mint Multiplier NFT (+1.2% APY boost)mintAccess(to)- Mint Access NFT (VIP access)balanceOf(user)- Get user's NFT countgetUserBoost(user)- Get user's total boost percentage
4. Stablecoin Contract
- Address:
0x0165878A594ca255338adfa4d48449f69242Eb8F - Functions: Standard ERC20 functions
Frontend Integration
Contract Service (app/services/contractService.ts)
Central service that handles all contract interactions:
// Vault Operations
depositToVault(amount: string)
withdrawFromVault(amount: string)
getVaultBalance()
getUserVaultBalance()
// NFT Operations
mintGenesisNFT(to: string)
mintMultiplierNFT(to: string)
mintAccessNFT(to: string)
getUserNFTBalance(userAddress: string)
getUserNFTBoost(userAddress: string)
// Utility Functions
connectWallet()
checkWalletConnection()
getWalletBalance(address: string)
UI Components
1. Deposit Modal (src/components/DepositModal.tsx)
- Allows users to deposit ETH into vaults
- Shows transaction status and confirmation
- Calculates estimated yields
2. Withdraw Modal (src/components/WithdrawModal.tsx)
- Allows users to withdraw from vaults
- Shows available balance
- Includes warning messages
3. Vault Cards (app/vaults/page.tsx)
- Display vault information (APY, TVL, Risk)
- Connect to deposit/withdraw modals
- Show real-time data
4. NFT Cards (app/nfts/page.tsx)
- Display NFT collections with minting functionality
- Show boost percentages and rarity
- Handle minting transactions
How It Works
1. Wallet Connection
// User connects wallet
const address = await connectWallet();
// Check connection status
const isConnected = await checkWalletConnection();
2. Vault Interactions
// Deposit into vault
await depositToVault("0.5"); // 0.5 ETH
// Withdraw from vault
await withdrawFromVault("0.2"); // 0.2 ETH
// Check balances
const vaultBalance = await getVaultBalance();
const userBalance = await getUserVaultBalance();
3. NFT Minting
// Mint different NFT types
await mintGenesisNFT(userAddress); // +2.5% boost
await mintMultiplierNFT(userAddress); // +1.2% boost
await mintAccessNFT(userAddress); // VIP access
// Check user's NFT status
const nftCount = await getUserNFTBalance(userAddress);
const totalBoost = await getUserNFTBoost(userAddress);
Transaction Flow
Deposit Process
- User enters amount in DepositModal
- Frontend calls
depositToVault(amount) - Contract receives ETH and updates balance
- Transaction hash returned to UI
- Success message shown to user
NFT Minting Process
- User clicks "Mint NFT" button
- Frontend calls appropriate mint function
- Contract mints NFT and sets boost
- Transaction confirmed
- User receives NFT with permanent benefits
Error Handling
All contract functions include comprehensive error handling:
try {
const tx = await depositToVault(amount);
// Show success message
} catch (error) {
// Show error message to user
console.error('Transaction failed:', error.message);
}
Network Configuration
- Network: Somnia Network (or localhost for development)
- Chain ID: Configure in wallet
- Gas Settings: Automatically estimated
Development Setup
-
Start local blockchain:
npx hardhat node -
Deploy contracts:
node deploy-updated-contracts.js -
Update contract addresses in
contractService.ts -
Start frontend:
npm run dev
Testing
The application includes built-in transaction testing:
- Deposit/withdraw functionality
- NFT minting for all types
- Balance checking
- Boost calculation
Security Features
- Input validation on all amounts
- Transaction confirmation UI
- Error handling for failed transactions
- MetaMask integration for secure signing
- Real-time balance updates
Next Steps
- Deploy updated contracts with
deploy-updated-contracts.js - Update contract addresses in frontend
- Test all functionality with MetaMask
- Monitor transactions and user interactions