Documentación

Referencia de tipos de TypeScript

Todos los tipos se exportan desde la raíz del paquete:

TypeScript
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

TypeScript
enum Network {
  POLYGON   = 'polygon',
  AMOY      = 'amoy',       // Polygon testnet
  CELO      = 'celo',
  ALFAJORES = 'alfajores',  // Celo testnet (EAS only — no EnergyAS contracts)
}

EnergyType

TypeScript
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

Duraciones predefinidas del intervalo de lectura, en minutos. Pásalas a readingIntervalMinutes en AttestParams o ZeroPeriodParams:

TypeScript
enum Interval {
  Hourly     = 60,
  FourHours  = 240,
  EightHours = 480,
  TwelveHours = 720,
  Daily      = 1440,
  Weekly     = 10080,
  Biweekly   = 20160,
  FourWeeks  = 40320,
}

Tipos de configuración

EnergyQueryConfig

Se pasa al constructor de EnergyQuery:

TypeScript
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

Se pasa a EnergySDK.fromPrivateKey():

TypeScript
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

Se pasa a EnergySDK.fromSigner():

TypeScript
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;
}

Tipos de operaciones de escritura

AttestParams

Parámetros para enviar un registro de energía individual:

TypeScript
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

Parámetros para corregir un registro existente. Extiende AttestParams:

TypeScript
interface OverwriteAttestParams extends AttestParams {
  /** UID of the record being corrected. */
  refUID: string;
}

ZeroPeriodParams

Parámetros de attestations.attestZeroPeriod(). Continúa automáticamente desde el último timestamp atestado del proyecto:

TypeScript
interface ZeroPeriodParams {
  projectId: number;
  interval: Interval;
  /** Defaults to "0 report" if omitted. */
  method?: string;
  metadataURI?: string;
}

Tipos de resultado

TypeScript
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;
}

Tipos de entidades del subgraph

Estos son los tipos que devuelven los métodos de EnergyQuery. Todos los campos BigInt de GraphQL se serializan como string para evitar la pérdida de precisión de JavaScript; conviértelos con BigInt(value) cuando necesites hacer aritmética.

SubgraphProtocol

TypeScript
interface SubgraphProtocol {
  totalWatchers: number;
  totalProjects: number;
  totalAttestations: number;
  totalGeneratedWh: string;   // BigInt as string
  totalConsumedWh: string;    // BigInt as string
  energyTypeAdmin: string;    // address
}

SubgraphEnergyType

TypeScript
interface SubgraphEnergyType {
  id: string;           // uint8 as string, e.g. "1"
  name: string;
  registered: boolean;
  totalGeneratedWh: string;
}

SubgraphWatcher

Lo devuelve getWatchers():

TypeScript
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

Lo devuelve getWatcher(); extiende SubgraphWatcher con todos los datos relacionados:

TypeScript
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

Lo devuelven getProjects() y getProject():

TypeScript
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

Lo devuelven getAttestations() y getAttestation():

TypeScript
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

Lo devuelve getDailySnapshots():

TypeScript
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

Lo devuelven getProjectAttesters() y getWatcherAttesters():

TypeScript
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

Lo devuelve getWatcherOwnershipHistory():

TypeScript
interface SubgraphWatcherOwnershipTransfer {
  id: string;           // "{txHash}-{logIndex}"
  previousOwner: string;
  newOwner: string;
  timestamp: string;
  blockNumber: string;
  txHash: string;
  watcher: { id: string; name: string };
}

Tipos de filtros

WatcherFilters

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
interface AttesterFilters {
  first?: number;
  skip?: number;
  active?: boolean;
}