A comprehensive decentralized betting platform built with Next.js, Node.js, and Solidity smart contracts. Users can place bets on cryptocurrency price movements using AVAX tokens. Chainlink is used for secure price feeds, randomness, and data streams throughout the stack.
- Framework: Next.js 14 with TypeScript
- Styling: Tailwind CSS with custom components
- State Management: Redux Toolkit
- Wallet Integration: Reown AppKit
- Charts: TradingView Widget
- UI Components: Custom neumorphic design system
- Chainlink: Data Streams, price feeds, and lottery randomness
- Framework: Express.js with TypeScript
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT tokens
- Blockchain Integration: Ethers.js
- Event Listening: Real-time blockchain event processing
- Chainlink: Listens to contract events powered by Chainlink
- Framework: Hardhat
- Network: Avalanche Fuji Testnet
- Contracts: Betting, Vault, Carbon Credits, Lottery
- Chainlink: VRF, Price Feeds, Automation, Functions
Chronix leverages Chainlink for:
- Price Feeds (secure, decentralized market data)
- VRF (verifiable randomness for lotteries)
- Automation (automated contract execution)
- Functions/Data Streams (off-chain computation and data)
Files using or referencing Chainlink:
src/components/dashboard/LotteryStatus.tsxβ Mentions Chainlink VRF for lottery randomness.src/app/page.tsxβ Mentions Chainlink-powered lottery in the description.
smartcontract/contracts/LotteryContract.solβ Imports Chainlink VRF and Automation contracts.smartcontract/contracts/CarbonCredit.solβ Imports Chainlink AggregatorV3Interface for price feeds.smartcontract/contracts/BettingNew.solβ Imports Chainlink Automation, Functions, and Owner contracts; references Chainlink Data Streams API.smartcontract/scripts/deploy.jsβ References Chainlink feed addresses and subscription IDs.
chronix/
βββ frontend/ # Next.js frontend application
β βββ src/
β β βββ app/ # App router pages
β β βββ components/ # React components
β β βββ hooks/ # Custom React hooks
β β βββ lib/ # Utilities and services
β β βββ store/ # Redux store
β β βββ abis/ # Contract ABIs
β βββ public/ # Static assets
βββ backend/ # Express.js backend server
β βββ src/
β β βββ controllers/ # API controllers
β β βββ routes/ # API routes
β β βββ services/ # Business logic
β β βββ lib/ # Database and utilities
β β βββ abi/ # Contract ABIs
β βββ prisma/ # Database schema and migrations
β βββ scripts/ # Utility scripts
βββ smartcontract/ # Solidity smart contracts
βββ contracts/ # Smart contract source code
βββ scripts/ # Deployment scripts
βββ test/ # Contract tests
- Node.js (v18 or higher)
- npm or yarn
- PostgreSQL database
- MetaMask or compatible wallet
- AVAX tokens for testing (Fuji testnet)
git clone <repository-url>
cd chronixCreate .env files in each directory:
NEXT_PUBLIC_BACKEND_URL=http://localhost:5000
NEXT_PUBLIC_CONTRACT_ADDRESS=0x4d2Fb695465c8fbbCFb2b9E424093BBdFC4E612B
NEXT_PUBLIC_VAULT_ADDRESS=0x...
NEXT_PUBLIC_NETWORK_ID=43113DATABASE_URL="postgresql://username:password@localhost:5432/chronix_db"
JWT_SECRET=your_jwt_secret_here
BTC_BETTING_CONTRACT_ADDRESS=0x4d2Fb695465c8fbbCFb2b9E424093BBdFC4E612B
AVALANCHE_FUJI_RPC_URL=https://api.avax-test.network/ext/bc/C/rpc
PORT=5000PRIVATE_KEY=your_private_key_here
AVALANCHE_FUJI_RPC_URL=https://api.avax-test.network/ext/bc/C/rpccd backend
npm install
npx prisma generate
npx prisma db push# Frontend
cd frontend
npm install
# Backend
cd ../backend
npm install
# Smart Contracts
cd ../smartcontract
npm installcd smartcontract
npx hardhat compile
npx hardhat run scripts/deploy.js --network fujiNote: Update the contract addresses in your environment files after deployment.
cd backend
npm run devThe backend will start on http://localhost:5000
cd frontend
npm run devThe frontend will start on http://localhost:3000
- Dashboard: Real-time trading charts and betting interface
- Vault Management: Deposit/withdraw AVAX tokens
- Betting Interface: Place long/short bets on BTC price movements
- Bet History: View all past bets with statistics
- Wallet Integration: Connect MetaMask or other wallets
- Responsive Design: Works on desktop and mobile
- RESTful API: Complete betting and user management
- Real-time Event Listening: Captures blockchain events
- User Authentication: JWT-based authentication
- Database Management: PostgreSQL with Prisma ORM
- Bet Statistics: Win/loss tracking and analytics
- Betting Contract: Handles bet placement and settlement
- Vault Contract: Manages user deposits and withdrawals
- Price Oracle Integration: Chainlink price feeds
- Carbon Credits: Environmental impact tracking
- Lottery System: Prize distribution mechanism
cd frontend
npm run dev # Start development server
npm run build # Build for production
npm run lint # Run ESLintcd backend
npm run dev # Start development server
npm run build # Build TypeScript
npm run start # Start production servercd smartcontract
npx hardhat compile # Compile contracts
npx hardhat test # Run tests
npx hardhat node # Start local nodePOST /api/auth/login- User loginPOST /api/auth/register- User registrationPOST /api/auth/verify- Verify JWT token
GET /api/bets- Get all bets with paginationGET /api/bets/user/:address- Get user's betsGET /api/bets/stats- Get betting statisticsGET /api/bets/recent- Get recent bets
POST /api/events/restart- Restart event listenerPOST /api/events/process-historical- Process historical eventsGET /api/events/status- Get event listener status
- Click "Connect Wallet" in the header
- Approve the connection in MetaMask
- Ensure you're on Avalanche Fuji testnet
- Click the "+" button next to your vault balance
- Enter the amount of AVAX to deposit
- Confirm the transaction
- Navigate to the Dashboard
- Select your bet amount (0.1, 0.5, 1.0 AVAX or custom)
- Choose Long (price up) or Short (price down)
- Confirm the bet transaction
- Bets settle after 5 minutes
- The system compares start and end prices
- Winners receive their payout automatically
- Check the Bet History section
- View your win/loss statistics
- Track all your betting activity
cd backend
node scripts/restart-events.js allcd backend
npx prisma db push
npx prisma generatecd smartcontract
npx hardhat clean
npx hardhat compile
npx hardhat run scripts/deploy.js --network fujicd frontend
rm -rf .next
npm run build# Check backend status
curl http://localhost:5000/api/health
# Check bet statistics
curl http://localhost:5000/api/bets/stats
# Restart event listener
curl -X POST http://localhost:5000/api/events/restart
# Process recent events
curl -X POST http://localhost:5000/api/events/process-historical \
-H "Content-Type: application/json" \
-d '{"recent": true}'- Private Keys: Never commit private keys to version control
- Environment Variables: Use
.envfiles for sensitive data - Database: Use strong passwords and secure connections
- Smart Contracts: All contracts are audited and tested
- API Security: JWT tokens with proper expiration
- Frontend: Optimized with Next.js 14 and React 18
- Backend: Efficient event processing with chunked queries
- Database: Indexed queries for fast bet retrieval
- Blockchain: Optimized for Avalanche network
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the troubleshooting section
- Review the API documentation
Stay updated with the latest changes:
- Monitor the repository for updates
- Check the changelog for new features
- Follow the deployment instructions
Note: This is a testnet deployment. For mainnet deployment, ensure all security measures are in place and contracts are thoroughly audited.