Registering an Organization
Your organization (called a Watcher in the protocol) is your identity on EnergyAS. Once registered, you can create projects, authorize devices to submit readings, and start building a verifiable energy track record.
For a complete working example that combines all steps, see the End-to-End Integration tutorial.
1. Register Your Organization
Registration is open to anyone — no approval needed, no fees beyond the transaction cost.
Using the SDK
import { EnergySDK } from 'energy-attestation-sdk';
const sdk = await EnergySDK.fromPrivateKey({
network: 'amoy', // or 'polygon', 'celo'
privateKey: process.env.PRIVATE_KEY,
});
const { watcherId, txHash } = await sdk.watchers.createWatcher('Greenfield Energy');
console.log('Organization ID:', watcherId.toString());Using the contract directly
const tx = await registry.registerWatcher('Greenfield Energy');
const receipt = await tx.wait();
// Extract watcherId from the WatcherRegistered event in receipt.logs2. Create a Project
Projects represent individual energy sites — a solar farm, wind turbine, data center, or any facility that generates or consumes energy.
Using the SDK
import { EnergyType } from 'energy-attestation-sdk';
const { projectId } = await sdk.projects.createProject(
watcherId,
'Solar Farm Alpha',
EnergyType.SOLAR_PV, // or any EnergyType enum value
);
console.log('Project ID:', projectId.toString());Using the contract directly
const tx = await registry.registerProject(
watcherId,
'Solar Farm Alpha',
1, // 1 = Solar PV; 0 = consumer
);
const receipt = await tx.wait();
// Extract projectId from the ProjectRegistered eventEnergy type is permanent. A project cannot switch between generator and consumer after registration. This protects the integrity of historical records.
3. Authorize Submitters
Before any device or script can submit readings for a project, it must be authorized. There are two authorization levels — a wallet only needs one:
Per-project authorization (recommended for IoT devices)
// SDK
await sdk.attesters.addAttester(projectId, '0xDeviceWalletAddress');
// Contract directly
await registry.addAttester(projectId, '0xDeviceWalletAddress');If a device is compromised, revoke only that device — the rest of the organization is unaffected.
Organization-wide authorization (for manual operators or auditors)
// SDK
await sdk.attesters.addWatcherAttester(watcherId, '0xOperatorAddress');
// Contract directly
await registry.addWatcherAttester(watcherId, '0xOperatorAddress');4. Attach Project Metadata (Optional)
Link supporting documents to a project — location data, capacity specifications, compliance certificates:
// SDK
await sdk.projects.setProjectMetadataURI(projectId, 'ipfs://Qm...');
// Contract directly
await registry.setProjectMetadataURI(projectId, 'ipfs://Qm...');See Project Metadata for the expected JSON format.
Ongoing Management
| Action | SDK method | Contract function |
|---|---|---|
| Remove a device | sdk.attesters.removeAttester(projectId, addr) | registry.removeAttester(projectId, addr) |
| Rotate multiple devices at once | sdk.attesters.addAttesters(projectId, addrs) | registry.addAttesters(projectId, addrs) |
| Deregister an inactive project | sdk.projects.deregisterProject(projectId) | registry.deregisterProject(projectId) |
| Transfer a project to another org | sdk.projects.transferProject(projectId, toWatcherId) | registry.transferProject(projectId, toWatcherId) |
| Transfer organization ownership | sdk.watchers.transferWatcherOwnership(watcherId, addr) | registry.transferWatcherOwnership(watcherId, addr) |
Deregistered projects stop accepting new submissions, but all historical records remain permanently on-chain.