A Solidity smart contract for tracking energy usage data from IoT devices with aggregation capabilities.
- Device registration and management
- Energy usage data recording
- Daily and monthly data aggregation
- Data retention policy implementation
- Role-based access control for device owners
The EnergyTracker contract provides the following main functionalities:
registerDevice
: Register new energy monitoring devicesrecordEnergyUsage
: Record energy consumption datagetDeviceEnergyData
: Retrieve historical energy datagetMonthlyAggregate
: Get monthly usage summariescleanupOldData
: Maintain data retention policy
- Install dependencies:
npm install
- Run tests:
npx hardhat test
- Deploy contract:
npx hardhat run scripts/deploy.ts
The test suite covers:
- Device registration scenarios
- Energy usage recording
- Data retrieval operations
- Access control validation
- Solidity Version: ^0.8.28
- Framework: Hardhat
- Testing: Chai & Hardhat Network Helpers
UNLICENSED
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat ignition deploy ./ignition/modules/Lock.ts