WattSwap
A peer-to-peer Renewable Energy Trading Platform
Created on 20th April 2026
•
WattSwap
A peer-to-peer Renewable Energy Trading Platform
The problem WattSwap solves
âš¡ Wattswap: Decentralized P2P Energy Trading
📋 Overview
This project explores a transformative initiative aimed at disrupting the traditional energy sector. By tackling electricity rate monopolies, providing for underserved rural areas, and accelerating the adoption of renewable energy, our platform paves the way for a more equitable and sustainable future.
🛠The Technical Solution
Our platform leverages a decentralized peer-to-peer (P2P) architecture to democratize energy access. The core stack includes:
- Blockchain Integration: Utilizes secure smart contracts to facilitate transparent trading.
- Hardware Layer: Integration of WiFi modules and time sensors for real-time tracking.
- Energy Management: An advanced Battery Management System (BMS) coupled with custom hardware for seamless energy transfer.
🌟 Key Benefits
- Empowered Sellers: Users set their own prices, fostering competition and driving down costs.
- Bridging the Gap: Surplus renewable energy is redistributed to "energy deserts" or underserved regions.
- Environmental Impact: Drastically reduces greenhouse gas emissions by incentivizing renewable sources.
🚧 Challenges & Resilience
While we recognize hurdles such as regulatory compliance, scalability, and user education, our solution remains robust through:
- User-Friendly Interface: Simplifying complex energy trading for the average consumer.
- Automated Security: Implementing smart contracts to ensure trustless transactions.
- Innovative Redistribution: A unique mechanism designed specifically for equitable distribution.
🚀 The Vision
This project underscores the potential of decentralized technology to combat monopolies and bridge the energy divide. We aren't just building a platform; we are accelerating the global adoption of renewable energy for a truly inclusive future.
Challenges I ran into
Challenge 1 — Battery State Management in a Distributed Energy Architecture
The Problem
Efficiently orchestrating the charging and discharging cycles across all battery systems in the network proved to be one of the most complex hardware-software co-design challenges of the project. Key difficulties included:
- State-of-Charge (SoC) synchronization — Each battery node needed to continuously broadcast its current energy capacity so the trading contract could make informed match-making decisions. Stale or out-of-sync SoC readings led to over-commitment of energy supply.
- Charge/discharge conflict resolution — When a node was simultaneously matched as both a buyer and a seller across different trade windows, concurrent read-write operations on battery state created race conditions in the coordination logic.
- Threshold enforcement — Defining safe operational boundaries (minimum SoC floors to protect battery health, maximum discharge rates) required these physical constraints to be reflected at both the firmware level and within the smart contract's business logic — keeping two systems in agreement at all times.
Approach
A buffered state management layer was introduced between the hardware sensors and the contract, decoupling the physical battery cycle from the on-chain trading logic. Battery state was treated as an eventually consistent value with defined staleness thresholds, beyond which a node's trading eligibility was automatically suspended until a fresh reading was confirmed.
Challenge 2 — Real-Time Firebase ↔ Solidity Smart Contract Integration
The Problem
Bridging a Web2 real-time database with a Web3 smart contract introduced a class of integration challenges that neither system was natively designed to solve:
- Oracles and trust boundaries — Smart contracts cannot natively read from external data sources. Feeding Firebase sensor data into Solidity required an off-chain relay mechanism to act as a trusted data bridge, raising questions about data integrity and manipulation resistance.
- Event latency and finality — Firebase updates arrive in near real-time (sub-second), whereas Ethereum transactions require block confirmations. A sensor spike that triggered a trade could be confirmed on-chain seconds or minutes later, by which time the underlying energy state had changed.
- Webhook-to-transaction mapping — Designing a reliable listener that translated Firebase
onValuechange events into signed Ethereum transactions, without message loss or duplicate submissions, required idempotency safeguards in the relay service.
Approach
An off-chain relay service (middleware layer) was built to subscribe to Firebase events, validate and normalize incoming sensor data, and submit structured transactions to the deployed contract. Idempotency keys were derived from the Firebase document ID and timestamp to prevent duplicate on-chain writes. Data was scaled to fixed-point integers (multiplied by 10³) before submission to preserve decimal precision within Solidity's integer type system.
Challenge 3 — Vulnerabilities in the Energy Supply Transfer Process
The Problem
A cascade of software bugs and security considerations surfaced specifically around the supply transfer workflow:
- Reentrancy exposure — Early iterations of the settlement function updated balances after triggering external calls, creating a classic reentrancy attack surface. A malicious contract acting as a buyer could re-enter the transfer function before state was finalized, enabling double-spend of energy credits.
- Partial fulfillment edge cases — If a seller's available supply dropped (due to a concurrent discharge event) between trade matching and settlement, the contract had no graceful mechanism to handle partial fills. Transactions would either revert entirely or settle for incorrect amounts, both unacceptable in an energy market context.
- Atomic settlement failure — The physical energy dispatch and the on-chain token transfer needed to succeed or fail together. Without a native two-phase commit mechanism on the blockchain, ensuring atomicity between the off-chain hardware action and the on-chain state change required a commit-reveal pattern with timeout-based rollback logic.
Approach
The settlement contract was refactored using the Checks-Effects-Interactions (CEI) pattern to eliminate reentrancy vectors. A ReentrancyGuard modifier was applied to all externally callable settlement functions. Batch settlement was redesigned with bounded iteration and a paginated settlement queue to stay within gas limits. Partial fulfillment was handled via a pro-rata allocation model, where trades were settled for the minimum of committed supply and verified available supply at execution time. Front-running mitigation was approached through a commit-reveal scheme for trade submissions, obscuring order intent until reveal phase
Cheer Project
Cheering for a project means supporting a project you like with as little as 0.0025 ETH. Right now, you can Cheer using ETH on Arbitrum, Optimism and Base.
