This project is a comprehensive decentralized energy trading platform that enables peer-to-peer energy transactions using blockchain technology. It combines a React frontend, Go backend for phase balancing, and Ethereum smart contracts to create a seamless energy trading ecosystem.
-
User Registration & Authentication
- User creates an account
- Connects MetaMask wallet
- Completes KYC verification
-
Energy Production & Monitoring
- Smart meters record energy production
- Data sent to Phase Balancer via Kafka
- Real-time monitoring through WebSocket
-
Phase Balancing
- Go backend processes meter readings
- Calculates optimal phase distribution
- Updates phase assignments in Redis
- Notifies frontend via WebSocket
-
Energy Trading
- Producer lists excess energy
- Energy tokens minted (ERC20)
- Consumers browse available energy
- Smart contract handles P2P trading
- USDT used for settlements
-
Transaction Settlement
- Smart contract verifies balance
- Executes token transfer
- Updates energy allocation
- Records transaction on blockchain
-
Monitoring & Reporting
- Dashboard shows real-time metrics
- Energy consumption patterns
- Trading history
- Phase balance status
graph TD
A[Smart Meter] -->|Readings| B[Kafka]
B --> C[Phase Balancer]
C -->|Updates| D[Redis Cache]
C -->|Notifications| E[WebSocket]
E --> F[Frontend Dashboard]
G[User] -->|Trade| H[Smart Contract]
H -->|Settlement| I[Blockchain]
I -->|Confirmation| F
- 🔐 Secure Authentication: User authentication and authorization system
- 💡 Energy Trading: P2P energy token trading with USDT payments
- ⚡ Phase Balancing: Real-time power grid phase balancing
- 📊 Dashboard: Live monitoring of energy usage and transactions
- 🔄 Smart Contracts: ERC20 tokens for energy trading
- 📱 Responsive UI: Modern, mobile-friendly interface
├── clientt/ # React frontend application
├── contracts/ # Smart contracts
├── my-foundry-project/ # Ethereum development environment
├── phase-balancer/ # Go backend for phase management
└── server/ # Node.js backend server
- Frontend: React, Vite, TailwindCSS
- Backend: Node.js, Go
- Blockchain: Ethereum, Solidity, Foundry
- Message Queue: Apache Kafka
- Cache: Redis
- WebSocket: Real-time updates
- Node.js (v16+)
- Go (v1.19+)
- Redis Server
- Apache Kafka
- Foundry
- MetaMask wallet
-
Clone the repository
git clone https://github.com/yourusername/p2p-energy-trading.git cd p2p-energy-trading
-
Frontend Setup
cd clientt npm install cp .env.example .env
-
Server Setup
cd server npm install cp .env.example .env
-
Phase Balancer Setup
cd phase-balancer go mod tidy
-
Smart Contract Setup
cd my-foundry-project forge install
-
Server (.env)
BLOCKCHAIN_RPC_URL=<your_rpc_url> PRIVATE_KEY=<your_private_key> ENERGY_TOKEN_ADDRESS=<energy_token_contract_address> USDT_TOKEN_ADDRESS=<usdt_token_contract_address>
-
Client (.env)
VITE_API_URL=http://localhost:3000 VITE_WS_URL=ws://localhost:8080
-
Start Redis
redis-server
-
Start Kafka
# Start Zookeeper bin/zookeeper-server-start.sh config/zookeeper.properties # Start Kafka Server bin/kafka-server-start.sh config/server.properties
-
Start Frontend
cd clientt npm run dev
-
Start Backend Server
cd server npm start
-
Start Phase Balancer
cd phase-balancer go run main.go
-
Smart Contracts
cd my-foundry-project forge test
-
Frontend
cd clientt npm test
-
Backend
cd server npm test
- Frontend: http://localhost:5173
- Backend API: http://localhost:3000
- WebSocket: ws://localhost:8080
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE.md file for details.
For support, please open an issue in the repository.