A Telegram Mini App for decentralized lending and borrowing, integrating with Compound Protocol for on-chain DeFi operations. Built with Next.js and optimized for Telegramβs WebApp environment.
This is a Telegram Mini App (not a traditional web application) that allows users to:
The app is designed to run inside Telegramβs WebApp environment, providing a native mobile experience with seamless wallet integration.
git clone https://github.com/itsored/compound-mini.git
cd compound-mini
# Install main app dependencies
npm install
# Install onchain dependencies (for local development)
cd onchain
npm install
cd ..
Create a .env.local file in the root directory:
# Network configuration (choose one)
NEXT_PUBLIC_NETWORK=sepolia # or 'local' for mainnet fork
# RPC Provider (for Sepolia testnet)
NEXT_PUBLIC_INFURA_KEY=your_infura_project_id
# OR
NEXT_PUBLIC_ALCHEMY_KEY=your_alchemy_api_key
# WalletConnect Project ID (required for wallet connections)
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_walletconnect_project_id
# Optional: Custom Sepolia RPC URL
NEXT_PUBLIC_SEPOLIA_RPC_URL=https://sepolia.publicnode.com
Get your WalletConnect Project ID:
The app supports two network modes:
# Set network to Sepolia testnet
echo 'NEXT_PUBLIC_NETWORK=sepolia' > .env.local
# Add RPC provider (choose one)
echo 'NEXT_PUBLIC_INFURA_KEY=your_infura_project_id' >> .env.local
# OR
echo 'NEXT_PUBLIC_ALCHEMY_KEY=your_alchemy_api_key' >> .env.local
For local development with a mainnet fork:
# Set network to local mainnet fork
echo 'NEXT_PUBLIC_NETWORK=local' > .env.local
# Configure mainnet fork (in onchain directory)
cd onchain
echo 'ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_KEY' > .env
echo 'FORK_BLOCK=23378885' >> .env
cd ..
π See NETWORK_CONFIG.md for detailed network configuration guide
# Switch to local mainnet fork
npm run switch:local
# Switch to Sepolia testnet
npm run switch:sepolia
# Test Sepolia connection
npm run test:sepolia
npm run dev
The app will be available at http://localhost:3000
Note: When running locally, the app will use a mock Telegram WebApp implementation for development. To test as a real Telegram Mini App, you need to deploy and configure it with a Telegram bot (see below).
Deploy your application to a hosting service that provides HTTPS:
Option A: Vercel (Recommended)
Option B: Other Hosting Services
Any hosting service that provides HTTPS will work (Netlify, Railway, etc.)
/newbot and follow instructions to create your bot/newapp to create a new Mini Apphttps://your-app.vercel.app)/start)When testing in Telegram:
Local Development (Browser):
http://localhost:3000Telegram Mini App (Production):
For comprehensive testing with real Compound Protocol contracts:
Create a .env file in the onchain directory:
cd onchain
echo 'ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY' > .env
echo 'FORK_BLOCK=23378885' >> .env
Required Environment Variables:
ETH_RPC_URL: Your Alchemy or Infura mainnet RPC endpointFORK_BLOCK: The block number to fork from (optional, defaults to latest)cd onchain
npm run node
This starts a local Ethereum node forked from mainnet at http://localhost:8545
Test that you have real mainnet data:
# Check block number (should be your fork block)
curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
http://127.0.0.1:8545
# Check real contract (USDC should exist)
curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "latest"],"id":1}' \
http://127.0.0.1:8545
The Hardhat node provides 20 test accounts with 10,000 ETH each:
Account #0 (Primary Test Account):
0xf39fd6e51aad88f6f4ce6ab8827279cfffb922660xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80Default Hardhat mnemonic (for MetaMask import):
test test test test test test test test test test test junk
Add the local network to MetaMask:
http://127.0.0.1:8545To test DeFi functionality, youβll need WETH (Wrapped ETH). The application requires WETH for supply and borrow operations.
Wrap ETH for a single account:
cd onchain
npx hardhat run scripts/wrap-eth-simple.ts --network hardhat
Wrap ETH for multiple accounts (2 ETH each):
npx hardhat run scripts/wrap-multiple.ts --network hardhat
Wrap half of your ETH:
npx hardhat run scripts/wrap-half.ts --network hardhat
Expected Results:
Why WETH is needed:
Wrap ETH to WETH (Simple)
cd onchain
npx hardhat run scripts/wrap-eth-simple.ts --network hardhat
Wrap Half of Your ETH
npx hardhat run scripts/wrap-half.ts --network hardhat
Wrap Multiple Amounts
npx hardhat run scripts/wrap-multiple.ts --network hardhat
Check Comet Protocol Status
npx hardhat run scripts/check-comet.ts --network hardhat
Get WETH Price
npx hardhat run scripts/get-weth-price.ts --network hardhat
Test User Positions
npx hardhat run scripts/test-positions.ts --network hardhat
Seed Test Data
npx hardhat run scripts/seed.ts --network hardhat
Demo Supply & Borrow
npx hardhat run scripts/demo-supply-borrow.ts --network hardhat
cd onchain
npm run compile
compound-mini/
βββ app/ # Next.js app directory
β βββ borrow/ # Borrow page
β βββ supply/ # Supply page
β βββ withdraw/ # Withdraw page
β βββ repay/ # Repay page
β βββ dashboard/ # Dashboard page
β βββ history/ # Transaction history
βββ components/ # React components
β βββ ui/ # Reusable UI components
β βββ dashboard.tsx # Main dashboard
β βββ supply-form.tsx # Supply form component
β βββ borrow-form.tsx # Borrow form component
β βββ wallet-connect.tsx # Wallet connection UI
β βββ ... # Other components
βββ lib/ # Utility libraries
β βββ comet-onchain.ts # Compound Protocol integration
β βββ wagmi-provider.tsx # Web3 provider configuration
β βββ telegram-provider.tsx # Telegram WebApp integration
β βββ guest-mode.tsx # Guest mode functionality
β βββ utils.ts # Helper functions
βββ onchain/ # Hardhat project
β βββ scripts/ # Deployment & utility scripts
β βββ abis/ # Contract ABIs
β βββ hardhat.config.ts # Hardhat configuration
βββ types/ # TypeScript type definitions
β βββ telegram.d.ts # Telegram WebApp types
βββ public/ # Static assets
.env.local with network and API keysnpm run devhttp://localhost:3000 in browser (uses mock Telegram API).env file in onchain/ with your RPC URLcd onchain && npm run nodenpx hardhat run scripts/wrap-eth-simple.ts --network hardhatnpx hardhat run scripts/wrap-multiple.ts --network hardhatnpm run devNEXT_PUBLIC_NETWORKNEXT_PUBLIC_WALLETCONNECT_PROJECT_IDNEXT_PUBLIC_INFURA_KEY or NEXT_PUBLIC_ALCHEMY_KEYnpm run build
npm run start
Important: For Telegram Mini Apps, your deployment must:
.env.local or .env files to version controlgit checkout -b feature/amazing-featuregit commit -m 'Add amazing feature'git push origin feature/amazing-featureThis project is licensed under the MIT License.
For questions or support, please open an issue on GitHub or contact the development team.
Note: This is a Telegram Mini App. While it can be tested in a browser during development, it is designed to run within Telegramβs WebApp environment. For the best experience, test it as a deployed Telegram Mini App.