A decentralized, trustless marketplace for peer-to-peer energy trading on the Ethereum blockchain.
Traditional centralized energy grids are inefficient for handling distributed energy resources (DERs) like solar panels. Prosumers (producers + consumers) often lack a transparent, direct mechanism to sell excess energy to their neighbors, relying instead on centralized utility companies with unfavorable rates and delayed settlements.
This project solves this by creating a blockchain-based trading platform where energy acts as a digital asset. It enables automated, transparent, and immediate settlement between energy sellers (Prosumers) and buyers (Consumers) without intermediaries.
- Role-Based Access Control: Strict segregation between
Prosumers(authorized sellers) andConsumers(buyers) via aUserRegistrysmart contract. - Tokenized Energy (NRG): ERC-20 compliant
EnergyTokenrepresenting energy units, minted exclusively by an authorized Smart Meter Oracle to ensure physical-digital parity. - Trustless Market: A
Marketcontract that handles offer creation, token escrow, and atomic swaps (ETH for NRG), eliminating counterparty risk. - Automated Settlement: Immediate transfer of ownership and funds upon purchase execution.
- Security First: Leveraging OpenZeppelin's battle-tested standard libraries for token and ownership management.
- Smart Contracts: Solidity (v0.8.20)
- Development Framework: Hardhat
- Standards: ERC-20 (OpenZeppelin)
- Testing & Scripting: TypeScript, Mocha, Chai, Ethers.js v6
- Deployment: Hardhat Ignition
├── contracts/
│ ├── EnergyToken.sol # ERC-20 Token implementation (NRG)
│ ├── Market.sol # Marketplace logic (Offers, Buying)
│ └── UserRegistry.sol # User role management
├── ignition/ # Deployment modules
├── test/ # Automated tests
├── hardhat.config.ts # Configuration (Networks, Plugins)
└── package.json # Dependencies
-
Clone the repository
git clone <repository-url> cd p2p-energy-trade
-
Install dependencies
npm install
-
Compile contracts
npx hardhat compile
Execute the comprehensive test suite (Solidity + Mocha/Chai):
npx hardhat testDeploy the contracts to a local Hardhat Network node:
# Start a local node
npx hardhat node
# Deploy modules (in a separate terminal)
npx hardhat ignition deploy ignition/modules/Counter.ts --network localhost(Note: Update the Ignition module path to match your specific deployment script name if different from the default)
- Set your
SEPOLIA_PRIVATE_KEYusing the Hardhat Keystore or environment variables:npx hardhat keystore set SEPOLIA_PRIVATE_KEY - Deploy to Sepolia:
npx hardhat ignition deploy ignition/modules/Counter.ts --network sepolia
- Fork the repository.
- Create a 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.
Distributed under the ISC License. See package.json for details.