EnergyRegistry API
Complete function reference for the EnergyRegistry contract — the permanent state layer of the protocol.
Watcher Management
registerWatcher
registerWatcher(string name) → uint64 watcherIdRegister a new watcher. The caller becomes the owner. Fully permissionless — no approval required. Emits WatcherRegistered.
transferWatcherOwnership
transferWatcherOwnership(uint64 watcherId, address newOwner)Transfer ownership of a watcher to a new address. Only the current watcher owner can call this. Emits WatcherOwnershipTransferred.
getWatcher
getWatcher(uint64 watcherId) → WatcherReturns the Watcher struct (owner, registered, name).
isWatcherRegistered
isWatcherRegistered(uint64 watcherId) → boolgetNextWatcherId
getNextWatcherId() → uint64Returns the next watcher ID that will be assigned.
Project Management
registerProject
registerProject(uint64 watcherId, string name, uint8 energyType) → uint64 projectIdRegister a new project under a watcher. The energyType determines the project type: 0 = consumer (no generation source), 1–13+ = generator (specific energy source). Only the watcher owner can call this. Emits ProjectRegistered.
deregisterProject
deregisterProject(uint64 projectId)Deregister a project. Blocks new attestations but preserves all historical data and accumulators. Emits ProjectDeregistered.
transferProject
transferProject(uint64 projectId, uint64 toWatcherId)Transfer a project to another watcher. Migrates accumulated energy totals. The source watcher owner must call this. Emits ProjectTransferred.
getProject
getProject(uint64 projectId) → ProjectReturns the Project struct (watcherId, registered, energyType, name).
getProjectType
getProjectType(uint64 projectId) → uint8Returns the binary project type: 0 = generator (energyType > 0), 1 = consumer (energyType == 0).
getProjectEnergyType
getProjectEnergyType(uint64 projectId) → uint8Returns the stored energy type ID (0 for consumer, 1–13+ for specific generation source).
isProjectRegistered
isProjectRegistered(uint64 projectId) → boolgetWatcherProjects
getWatcherProjects(uint64 watcherId) → uint64[]Returns all project IDs under a watcher (including deregistered ones).
setProjectMetadataURI
setProjectMetadataURI(uint64 projectId, string uri)Set or update the metadata URI for a project. Watcher owner only. Emits ProjectMetadataURISet.
getProjectMetadataURI
getProjectMetadataURI(uint64 projectId) → stringAttester Management
addAttester
addAttester(uint64 projectId, address attester)Whitelist an attester for a specific project. Watcher owner only. Emits AttesterAdded.
removeAttester
removeAttester(uint64 projectId, address attester)Remove an attester from a project. Emits AttesterRemoved.
addAttesters
addAttesters(uint64 projectId, address[] attesters)Batch whitelist multiple attesters for a project.
removeAttesters
removeAttesters(uint64 projectId, address[] attesters)Batch remove multiple attesters from a project.
addWatcherAttester
addWatcherAttester(uint64 watcherId, address attester)Whitelist an attester for all projects under a watcher. Emits WatcherAttesterAdded.
removeWatcherAttester
removeWatcherAttester(uint64 watcherId, address attester)Remove a watcher-wide attester. Emits WatcherAttesterRemoved.
isProjectAttester
isProjectAttester(uint64 projectId, address attester) → boolisWatcherAttester
isWatcherAttester(uint64 watcherId, address attester) → boolEnergy Accumulators
getTotalGeneratedEnergy
getTotalGeneratedEnergy(uint64 projectId) → uint256Returns total generated energy in Wh for a project.
getTotalConsumedEnergy
getTotalConsumedEnergy(uint64 projectId) → uint256getTotalGeneratedEnergyByWatcher
getTotalGeneratedEnergyByWatcher(uint64 watcherId) → uint256getTotalConsumedEnergyByWatcher
getTotalConsumedEnergyByWatcher(uint64 watcherId) → uint256Period & Chain Lookup
getAttestedPeriodUID
getAttestedPeriodUID(uint64 projectId, uint64 fromTimestamp, uint64 toTimestamp) → bytes32Returns the UID of the attestation covering this period, or bytes32(0) if not attested.
getAttestedPeriodStartUID
getAttestedPeriodStartUID(uint64 projectId, uint64 fromTimestamp) → bytes32Returns the UID of the attestation starting at this timestamp, or bytes32(0).
getProjectLastTimestamp
getProjectLastTimestamp(uint64 projectId) → uint64Returns the last toTimestamp for the project's attestation chain. New attestations must start from this timestamp.
getReplacementUID
getReplacementUID(bytes32 uid) → bytes32Returns the UID of the attestation that replaced the given one, or bytes32(0) if not replaced. Follow the chain to find the latest version.
Energy Type Management
registerEnergyType
registerEnergyType(uint8 id, string name)Register a new energy source type. Energy type admin only. Emits EnergyTypeRegistered.
removeEnergyType
removeEnergyType(uint8 id)Remove an energy type. Energy type admin only. Emits EnergyTypeRemoved.
transferEnergyTypeAdmin
transferEnergyTypeAdmin(address newAdmin)Transfer the energy type admin role. Current admin only. Emits EnergyTypeAdminTransferred.
getEnergyTypeAdmin
getEnergyTypeAdmin() → addressgetEnergyTypeName
getEnergyTypeName(uint8 id) → stringisEnergyTypeRegistered
isEnergyTypeRegistered(uint8 id) → boolResolver Authorization
authorizeResolver
authorizeResolver(address resolver)Authorize a resolver to write to the registry. Contract owner only.
deauthorizeResolver
deauthorizeResolver(address resolver)isAuthorizedResolver
isAuthorizedResolver(address resolver) → bool