Documentation

EnergyRegistry API

Complete function reference for the EnergyRegistry contract — the permanent state layer of the protocol.

Watcher Management

registerWatcher

Solidity
registerWatcher(string name) → uint64 watcherId

Register a new watcher. The caller becomes the owner. Fully permissionless — no approval required. Emits WatcherRegistered.

transferWatcherOwnership

Solidity
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

Solidity
getWatcher(uint64 watcherId) → Watcher

Returns the Watcher struct (owner, registered, name).

isWatcherRegistered

Solidity
isWatcherRegistered(uint64 watcherId) → bool

getNextWatcherId

Solidity
getNextWatcherId() → uint64

Returns the next watcher ID that will be assigned.

Project Management

registerProject

Solidity
registerProject(uint64 watcherId, string name, uint8 energyType) → uint64 projectId

Register 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

Solidity
deregisterProject(uint64 projectId)

Deregister a project. Blocks new attestations but preserves all historical data and accumulators. Emits ProjectDeregistered.

transferProject

Solidity
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

Solidity
getProject(uint64 projectId) → Project

Returns the Project struct (watcherId, registered, energyType, name).

getProjectType

Solidity
getProjectType(uint64 projectId) → uint8

Returns the binary project type: 0 = generator (energyType > 0), 1 = consumer (energyType == 0).

getProjectEnergyType

Solidity
getProjectEnergyType(uint64 projectId) → uint8

Returns the stored energy type ID (0 for consumer, 1–13+ for specific generation source).

isProjectRegistered

Solidity
isProjectRegistered(uint64 projectId) → bool

getWatcherProjects

Solidity
getWatcherProjects(uint64 watcherId) → uint64[]

Returns all project IDs under a watcher (including deregistered ones).

setProjectMetadataURI

Solidity
setProjectMetadataURI(uint64 projectId, string uri)

Set or update the metadata URI for a project. Watcher owner only. Emits ProjectMetadataURISet.

getProjectMetadataURI

Solidity
getProjectMetadataURI(uint64 projectId) → string

Attester Management

addAttester

Solidity
addAttester(uint64 projectId, address attester)

Whitelist an attester for a specific project. Watcher owner only. Emits AttesterAdded.

removeAttester

Solidity
removeAttester(uint64 projectId, address attester)

Remove an attester from a project. Emits AttesterRemoved.

addAttesters

Solidity
addAttesters(uint64 projectId, address[] attesters)

Batch whitelist multiple attesters for a project.

removeAttesters

Solidity
removeAttesters(uint64 projectId, address[] attesters)

Batch remove multiple attesters from a project.

addWatcherAttester

Solidity
addWatcherAttester(uint64 watcherId, address attester)

Whitelist an attester for all projects under a watcher. Emits WatcherAttesterAdded.

removeWatcherAttester

Solidity
removeWatcherAttester(uint64 watcherId, address attester)

Remove a watcher-wide attester. Emits WatcherAttesterRemoved.

isProjectAttester

Solidity
isProjectAttester(uint64 projectId, address attester) → bool

isWatcherAttester

Solidity
isWatcherAttester(uint64 watcherId, address attester) → bool

Energy Accumulators

getTotalGeneratedEnergy

Solidity
getTotalGeneratedEnergy(uint64 projectId) → uint256

Returns total generated energy in Wh for a project.

getTotalConsumedEnergy

Solidity
getTotalConsumedEnergy(uint64 projectId) → uint256

getTotalGeneratedEnergyByWatcher

Solidity
getTotalGeneratedEnergyByWatcher(uint64 watcherId) → uint256

getTotalConsumedEnergyByWatcher

Solidity
getTotalConsumedEnergyByWatcher(uint64 watcherId) → uint256

Period & Chain Lookup

getAttestedPeriodUID

Solidity
getAttestedPeriodUID(uint64 projectId, uint64 fromTimestamp, uint64 toTimestamp) → bytes32

Returns the UID of the attestation covering this period, or bytes32(0) if not attested.

getAttestedPeriodStartUID

Solidity
getAttestedPeriodStartUID(uint64 projectId, uint64 fromTimestamp) → bytes32

Returns the UID of the attestation starting at this timestamp, or bytes32(0).

getProjectLastTimestamp

Solidity
getProjectLastTimestamp(uint64 projectId) → uint64

Returns the last toTimestamp for the project's attestation chain. New attestations must start from this timestamp.

getReplacementUID

Solidity
getReplacementUID(bytes32 uid) → bytes32

Returns 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

Solidity
registerEnergyType(uint8 id, string name)

Register a new energy source type. Energy type admin only. Emits EnergyTypeRegistered.

removeEnergyType

Solidity
removeEnergyType(uint8 id)

Remove an energy type. Energy type admin only. Emits EnergyTypeRemoved.

transferEnergyTypeAdmin

Solidity
transferEnergyTypeAdmin(address newAdmin)

Transfer the energy type admin role. Current admin only. Emits EnergyTypeAdminTransferred.

getEnergyTypeAdmin

Solidity
getEnergyTypeAdmin() → address

getEnergyTypeName

Solidity
getEnergyTypeName(uint8 id) → string

isEnergyTypeRegistered

Solidity
isEnergyTypeRegistered(uint8 id) → bool

Resolver Authorization

authorizeResolver

Solidity
authorizeResolver(address resolver)

Authorize a resolver to write to the registry. Contract owner only.

deauthorizeResolver

Solidity
deauthorizeResolver(address resolver)

isAuthorizedResolver

Solidity
isAuthorizedResolver(address resolver) → bool