Querying Data
All EnergyAS data is public and queryable by anyone — no API keys, no access controls. This guide covers common query patterns.
Using the Query Script
Terminal
npx hardhat run scripts/query-watcher.ts --network <network>Displays a watcher's total generated and consumed energy with a per-project breakdown.
Direct Contract Queries
JavaScript
const watcher = await registry.getWatcher(watcherId);
console.log(watcher.name, watcher.owner);
const projects = await registry.getWatcherProjects(watcherId);
console.log("Projects:", projects);JavaScript
const generated = await registry.getTotalGeneratedEnergy(projectId);
const consumed = await registry.getTotalConsumedEnergy(projectId);
console.log(`Generated: ${generated} Wh, Consumed: ${consumed} Wh`);JavaScript
const totalGen = await registry.getTotalGeneratedEnergyByWatcher(watcherId);
const totalCon = await registry.getTotalConsumedEnergyByWatcher(watcherId);JavaScript
const uid = await registry.getAttestedPeriodUID(
projectId, fromTimestamp, toTimestamp
);
const isAttested = uid !== ZeroHash;JavaScript
const isAuthorized =
await registry.isProjectAttester(projectId, wallet) ||
await registry.isWatcherAttester(watcherId, wallet);Event Indexing
For historical queries or building dashboards, index the events emitted by EnergyRegistry:
- EnergyAttested — every attestation with full details
- EnergyRevoked — every revocation
- ProjectRegistered / ProjectDeregistered — project lifecycle
- WatcherRegistered — new watcher onboarding
Use a subgraph (The Graph), an indexer (Ponder, Envio), or direct event log queries to build your data layer.