QubicTypeScript

getAbi

Returns the ABI version active at a given epoch, throwing AbiNotFoundError if no version covers it.

Signature

getAbi(registry: ContractRegistry, contractIndex: number, epoch: number): AbiLookupResult

Purpose

Returns the ABI version that was active at the given epoch. Use this when decoding historical data from a specific epoch.

import { getAbi } from "@qubic.org/registry"
import registry from "@qubic.org/registry/registry.json"
import type { ContractRegistry } from "@qubic.org/registry"

const reg = registry as ContractRegistry

const { version, isCurrent, isRegistryPossiblyStale } = getAbi(reg, 9, 213)
// version: ContractAbiVersion
// isCurrent: true if effectiveToEpoch === null (still active)
// isRegistryPossiblyStale: true if isCurrent and epoch > the known-active range

Parameters

NameTypeDescription
registryContractRegistryThe imported registry JSON
contractIndexnumberContract index (e.g. 9 for Qearn, 1 for Qx) — or use CONTRACT_INDEX from @qubic.org/types
epochnumberThe epoch to look up

Returns

FieldTypeDescription
versionContractAbiVersionThe ABI version covering this epoch
isCurrentbooleantrue if this is the currently-active version
isRegistryPossiblyStalebooleantrue if isCurrent and the registry may be out of date

Throws

AbiNotFoundError — if no version covers the requested epoch.

import { AbiNotFoundError } from "@qubic.org/registry"

try {
  const { version } = getAbi(reg, 9, 50)  // epoch 50 predates Qearn
} catch (e) {
  if (e instanceof AbiNotFoundError) {
    console.error(`No ABI for contract ${e.contractIndex} at epoch ${e.epoch}`)
  }
}

Prefer CONTRACT_INDEX from @qubic.org/types over hardcoding numeric contract indices.

On this page