TypeScript Types Reference
All types are exported from the package root:
import type {
EnergyQueryConfig,
SubgraphProtocol,
SubgraphWatcher,
SubgraphProject,
SubgraphEnergyAttestation,
SubgraphDailySnapshot,
WatcherFilters,
ProjectFilters,
AttestationFilters,
AttestParams,
AttestResult,
BatchAttestResult,
CreateWatcherResult,
CreateProjectResult,
} from 'energy-attestation-sdk';
import { Network, EnergyType, Interval } from 'energy-attestation-sdk';Enums
Network
enum Network {
POLYGON = 'polygon',
AMOY = 'amoy', // Polygon testnet
CELO = 'celo',
ALFAJORES = 'alfajores', // Celo testnet (EAS only — no EnergyAS contracts)
}EnergyType
enum EnergyType {
CONSUMER = 0,
SOLAR_PV = 1,
WIND_ONSHORE = 2,
WIND_OFFSHORE = 3,
HYDRO = 4,
BIOMASS = 5,
GEOTHERMAL = 6,
OCEAN_TIDAL = 7,
NUCLEAR = 8,
NATURAL_GAS = 9,
COAL = 10,
OIL = 11,
STORAGE_DISCHARGE = 12,
HYDROGEN_FUEL_CELL = 13,
}Interval
Preset reading interval lengths in minutes. Pass to readingIntervalMinutes in AttestParams or ZeroPeriodParams:
enum Interval {
Hourly = 60,
FourHours = 240,
EightHours = 480,
TwelveHours = 720,
Daily = 1440,
Weekly = 10080,
Biweekly = 20160,
FourWeeks = 40320,
}Configuration Types
EnergyQueryConfig
Passed to the EnergyQuery constructor:
interface EnergyQueryConfig {
network: Network;
/** The Graph API key — required to access the deployed subgraphs */
apiKey?: string;
/** Override the subgraph URL directly (custom or self-hosted deployments) */
subgraphUrl?: string;
}PrivateKeySDKConfig
Passed to EnergySDK.fromPrivateKey():
interface PrivateKeySDKConfig {
network: Network;
/** Hex-encoded private key (with or without 0x prefix) */
privateKey: string;
/** JSON-RPC endpoint. Uses the network default if omitted. */
rpcUrl?: string;
/** Override contract addresses for custom deployments */
registryAddress?: string;
schemaUID?: string;
easAddress?: string;
}SignerSDKConfig
Passed to EnergySDK.fromSigner():
interface SignerSDKConfig {
network: Network;
/** An ethers AbstractSigner with an attached provider */
signer: AbstractSigner;
/** Override contract addresses for custom deployments */
registryAddress?: string;
schemaUID?: string;
easAddress?: string;
}Write Operation Types
AttestParams
Parameters for submitting a single energy record:
interface AttestParams {
projectId: number;
/** Per-interval readings in watt-hours. Use `0n` for zero-generation periods. */
readings: bigint[];
/** Minutes per reading. Accepts a plain number or an `Interval` enum value. */
readingIntervalMinutes: Interval | number;
/** Unix timestamp (seconds) of the start of the first interval. */
fromTimestamp: number;
/** Free-text label describing the collection method (e.g. "smart-meter-api"). */
method: string;
/** Optional URI pointing to supporting evidence (IPFS or HTTPS). */
metadataURI?: string;
}OverwriteAttestParams
Parameters for correcting an existing record. Extends AttestParams:
interface OverwriteAttestParams extends AttestParams {
/** UID of the record being corrected. */
refUID: string;
}ZeroPeriodParams
Parameters for attestations.attestZeroPeriod(). Automatically continues from the project's last attested timestamp:
interface ZeroPeriodParams {
projectId: number;
interval: Interval;
/** Defaults to "0 report" if omitted. */
method?: string;
metadataURI?: string;
}Result types
interface AttestResult {
uid: string; // EAS attestation UID (bytes32 hex)
txHash: string;
}
interface BatchAttestResult {
uids: string[]; // one UID per submitted record
txHash: string;
}
interface CreateWatcherResult {
watcherId: bigint;
txHash: string;
}
interface CreateProjectResult {
projectId: bigint;
txHash: string;
}
interface TxResult {
txHash: string;
}Subgraph Entity Types
These are the return types from EnergyQuery methods. All BigInt fields from GraphQL are serialized as string to avoid JavaScript precision loss — convert with BigInt(value) when arithmetic is needed.
SubgraphProtocol
interface SubgraphProtocol {
totalWatchers: number;
totalProjects: number;
totalAttestations: number;
totalGeneratedWh: string; // BigInt as string
totalConsumedWh: string; // BigInt as string
energyTypeAdmin: string; // address
}SubgraphEnergyType
interface SubgraphEnergyType {
id: string; // uint8 as string, e.g. "1"
name: string;
registered: boolean;
totalGeneratedWh: string;
}SubgraphWatcher
Returned by getWatchers():
interface SubgraphWatcher {
id: string; // watcherId as string
name: string;
owner: string; // address
registered: boolean;
totalGeneratedWh: string;
totalConsumedWh: string;
projectCount: number;
createdAt: string; // Unix timestamp as string
createdAtBlock: string;
}SubgraphWatcherDetail
Returned by getWatcher() — extends SubgraphWatcher with full relational data:
interface SubgraphWatcherDetail extends SubgraphWatcher {
projects: SubgraphProjectSummary[];
watcherAttesters: {
id: string;
attester: string;
active: boolean;
addedAt: string;
addedAtBlock: string;
}[];
ownershipHistory: {
id: string;
previousOwner: string;
newOwner: string;
timestamp: string;
blockNumber: string;
txHash: string;
}[];
}SubgraphProject
Returned by getProjects() and getProject():
interface SubgraphProject {
id: string; // projectId as string
name: string;
registered: boolean;
totalGeneratedWh: string;
totalConsumedWh: string;
lastToTimestamp: string; // end of the last attested period
metadataURI: string | null;
attestationCount: number;
createdAt: string;
createdAtBlock: string;
watcher: { id: string; name: string };
energyType: { id: string; name: string } | null; // null for consumer projects
}SubgraphEnergyAttestation
Returned by getAttestations() and getAttestation():
interface SubgraphEnergyAttestation {
id: string; // EAS UID (bytes32 hex)
fromTimestamp: string; // Unix timestamp as string
toTimestamp: string;
energyWh: string; // total Wh as string
attester: string; // address
metadataURI: string | null;
readings: string[]; // per-interval Wh values, each as string
replaced: boolean;
replacedBy: { id: string } | null;
replaces: { id: string } | null;
blockTimestamp: string;
blockNumber: string;
txHash: string;
project: { id: string; name: string };
energyType: { id: string; name: string } | null;
}SubgraphDailySnapshot
Returned by getDailySnapshots():
interface SubgraphDailySnapshot {
id: string; // "{projectId}-{YYYY-MM-DD}"
date: string; // "YYYY-MM-DD"
timestamp: string; // Unix timestamp of day start
generatedWh: string;
consumedWh: string;
attestationCount: number;
project: { id: string; name: string };
}SubgraphProjectAttester and SubgraphWatcherAttester
Returned by getProjectAttesters() and getWatcherAttesters():
interface SubgraphProjectAttester {
id: string; // "{projectId}-{attesterAddress}"
attester: string;
active: boolean;
addedAt: string;
addedAtBlock: string;
project: { id: string; name: string };
}
interface SubgraphWatcherAttester {
id: string; // "{watcherId}-{attesterAddress}"
attester: string;
active: boolean;
addedAt: string;
addedAtBlock: string;
watcher: { id: string; name: string };
}SubgraphWatcherOwnershipTransfer
Returned by getWatcherOwnershipHistory():
interface SubgraphWatcherOwnershipTransfer {
id: string; // "{txHash}-{logIndex}"
previousOwner: string;
newOwner: string;
timestamp: string;
blockNumber: string;
txHash: string;
watcher: { id: string; name: string };
}Filter Types
WatcherFilters
interface WatcherFilters {
first?: number; // default 100, max 1000
skip?: number; // default 0
orderBy?: 'createdAt' | 'totalGeneratedWh' | 'totalConsumedWh' | 'projectCount';
orderDirection?: 'asc' | 'desc';
registered?: boolean;
owner?: string; // filter by owner address
}ProjectFilters
interface ProjectFilters {
first?: number;
skip?: number;
orderBy?: 'createdAt' | 'totalGeneratedWh' | 'totalConsumedWh' | 'attestationCount';
orderDirection?: 'asc' | 'desc';
watcherId?: string; // filter by organization ID
energyTypeId?: string; // "0" for consumers, "1"–"13" for generators
registered?: boolean;
}AttestationFilters
interface AttestationFilters {
first?: number;
skip?: number;
orderBy?: 'fromTimestamp' | 'blockTimestamp' | 'energyWh';
orderDirection?: 'asc' | 'desc';
projectId?: string;
attester?: string;
replaced?: boolean; // use false to get only active records
fromTimestamp_gte?: string; // Unix seconds as string
fromTimestamp_lte?: string;
}DailySnapshotFilters
interface DailySnapshotFilters {
projectId: string; // required
dateFrom?: string; // 'YYYY-MM-DD' (inclusive)
dateTo?: string; // 'YYYY-MM-DD' (inclusive)
first?: number; // default 365
skip?: number;
orderDirection?: 'asc' | 'desc';
}AttesterFilters
interface AttesterFilters {
first?: number;
skip?: number;
active?: boolean;
}