Documentation

Quick Start

Submit your first verified energy record to EnergyAS in minutes. The contracts are already deployed on Polygon Amoy testnet — no deployment required.

Prerequisites

1. Install the SDK

Terminal
npm install energy-attestation-sdk

2. Set Up Your Environment

Create a .env file with your credentials:

Environment
PRIVATE_KEY=0x...your_wallet_private_key
THEGRAPH_API_KEY=your_api_key_here
Note

Use a dedicated wallet with only enough MATIC for gas. Never use your main wallet's private key in scripts.

3. Register an Organization

JavaScript
import 'dotenv/config';
import { EnergySDK } from 'energy-attestation-sdk';

const sdk = await EnergySDK.fromPrivateKey({
  network: 'amoy',
  privateKey: process.env.PRIVATE_KEY,
});

const { watcherId } = await sdk.watchers.createWatcher('My Energy Org');
console.log('Organization ID:', watcherId.toString());

The SDK automatically connects to the deployed contracts on Amoy — no addresses to configure.

4. Create a Project

JavaScript
import { EnergyType } from 'energy-attestation-sdk';

const { projectId } = await sdk.projects.createProject(
  watcherId,
  'Solar Farm Alpha',
  EnergyType.SOLAR_PV,
);
console.log('Project ID:', projectId.toString());

5. Authorize Your Wallet as a Submitter

JavaScript
await sdk.attesters.addAttester(projectId, sdk.address);
// sdk.address is the wallet you initialized the SDK with

6. Submit Your First Reading

JavaScript
import { Interval } from 'energy-attestation-sdk';

const { uid } = await sdk.attestations.attest({
  projectId: Number(projectId),
  readings: [250_000n, 310_000n, 280_000n],  // Wh per hour
  readingIntervalMinutes: Interval.Hourly,
  fromTimestamp: Math.floor(Date.now() / 1000) - 3 * 3600,  // 3 hours ago
  method: 'manual',
});

console.log('Record submitted! UID:', uid);

7. Query Your Data

Wait about a minute for the subgraph to index the transaction, then read it back:

JavaScript
import { EnergyQuery } from 'energy-attestation-sdk';

const query = new EnergyQuery({
  network: 'amoy',
  apiKey: process.env.THEGRAPH_API_KEY,
});

const org = await query.getWatcher(watcherId.toString());
console.log('Total generated:', org.totalGeneratedWh, 'Wh');

const records = await query.getAttestations({
  projectId: projectId.toString(),
  replaced: false,
});
console.log('Records:', records.length);

You can also browse your data on the EnergyAS Dashboard by selecting the Amoy network.

What's Next