A blockchain-based peer-to-peer energy trading platform built on Ethereum that enables users to buy and sell energy tokens representing kilowatt-hours (kWh) of renewable energy, enhanced with AI/ML predictive analytics for smart energy management.
- Token-Based Trading: Energy represented as KWh tokens (1 token = 0.01 kWh)
- Peer-to-Peer Marketplace: Users can create buy/sell orders for energy trading
- Secure Transactions: Direct token transfers between users
- Persistent Wallets: User wallet addresses stored for consistent transactions
- Real-Time Dashboard: Live monitoring of energy trades and balances
- Database Persistence: User balances maintained across blockchain redeployments
- Smart Meter Simulation: Realistic energy consumption data generation
- AI/ML Energy Forecasting: Predictive models for energy demand forecasting
- Responsive UI: Modern web interface for seamless trading experience
-
Smart Contracts (Solidity):
KWhToken.sol: ERC-20 compliant energy tokenMarket.sol: Trading marketplace for energy ordersMeterRegistry.sol: Smart meter verification system
-
Backend Services (Python):
- Flask API for user authentication and trading operations
- Blockchain integration layer for smart contract interactions
- PostgreSQL database for user data and order management
-
Frontend (HTML/CSS/JavaScript):
- Interactive dashboard for energy trading
- Real-time order book and transaction history
- User-friendly interface for creating and managing trades
-
Infrastructure:
- Hardhat for smart contract development and testing
- Local Ethereum node for development
- MQTT for IoT device communication (simulated meters)
- Machine Learning models for energy consumption prediction
- Node.js (v16 or higher)
- Python (3.8 or higher)
- PostgreSQL database
- Hardhat (for blockchain development)
-
Clone the repository:
git clone <repository-url> cd energy-trading-platform
-
Install blockchain dependencies:
cd blockchain npm install -
Start local blockchain:
npx hardhat node
-
Deploy smart contracts:
npx hardhat run scripts/deploy_contracts.js --network localhost
-
Install Python dependencies:
pip install -r requirements.txt
-
Set up database:
psql -f create_tables.sql
-
Start the application:
python api.py
-
Access the platform: Open
http://localhost:5001in your browser
- Initial Allocation: New users receive 10,000 KWh tokens upon signup
- Trading Mechanism:
- Buyers must hold sufficient tokens to purchase energy
- Sellers earn tokens when their energy is purchased
- 1 KWh token = 0.01 kWh of energy
- Price: Fixed at $0.16 USD per KWh token ($16 per token)
- Sign up to receive initial 10,000 KWh tokens
- Persistent wallet address assigned for all transactions
-
Sell Energy:
- Create sell orders specifying energy amount
- Tokens transferred to seller upon successful trade
-
Buy Energy:
- Browse available sell orders
- Purchase energy with tokens from your balance
- Realistic energy consumption data generation
- MQTT-based communication protocol
- Simulated meter readings for testing and demonstration
- Continuous data streaming for real-time monitoring
- Predictive models for energy demand forecasting
- 24-hour consumption forecasting using machine learning
- Personalized energy usage patterns based on historical data
- Random forest regression models for accurate predictions
- Token balances automatically synchronized with blockchain
- Balances persisted in database across sessions
- Automatic restoration after blockchain redeployment
# Compile contracts
npx hardhat compile
# Run tests
npx hardhat test
# Deploy to local network
npx hardhat run scripts/deploy_contracts.js --network localhost# Start API server
python api.py
# Run blockchain integration tests
python test_blockchain.pyenergy-trading-platform/
├── blockchain/ # Smart contracts and blockchain tools
│ ├── contracts/ # Solidity smart contracts
│ ├── scripts/ # Deployment scripts
│ └── test/ # Contract tests
├── api.py # Main Flask API server
├── blockchain_integration.py # Blockchain interaction layer
├── app.js # Frontend application logic
├── create_tables.sql # Database schema
└── index3.html # Main frontend interface
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Hardhat for Ethereum development
- Uses Web3.py for blockchain integration
- Powered by Flask for backend services
- PostgreSQL for data persistence