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): AbiLookupResultPurpose
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 rangeParameters
| Name | Type | Description |
|---|---|---|
registry | ContractRegistry | The imported registry JSON |
contractIndex | number | Contract index (e.g. 9 for Qearn, 1 for Qx) — or use CONTRACT_INDEX from @qubic.org/types |
epoch | number | The epoch to look up |
Returns
| Field | Type | Description |
|---|---|---|
version | ContractAbiVersion | The ABI version covering this epoch |
isCurrent | boolean | true if this is the currently-active version |
isRegistryPossiblyStale | boolean | true 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.