Skip to content

Oracles

Aeternity oracles provide a first-class mechanism for bringing off-chain data on-chain. Unlike EVM oracles that rely on contract-based solutions, AE oracles are a protocol-level primitive.

Overview

The oracle lifecycle:

  1. Register — create an oracle with query/response formats
  2. Query — anyone can query a registered oracle
  3. Respond — the oracle operator responds to queries
  4. Extend — extend the oracle's TTL before it expires

Registering an Oracle

typescript
import { registerOracle } from '@growae/reactive/actions'

const oracle = await registerOracle(config, {
  queryFormat: 'string',
  responseFormat: 'string',
})

console.log('Oracle ID:', oracle.id) // ok_...

Parameters

ParameterTypeDefaultDescription
queryFormatstringRequired. Expected query format description.
responseFormatstringRequired. Expected response format description.
queryFeebigint0nFee required per query (in aettos).
oracleTtlType'delta' | 'block''delta'TTL type for oracle registration.
oracleTtlValuenumber500Oracle TTL value in blocks.
ttlnumber300Transaction TTL in blocks relative to current height. Set to 0 for no expiration.

Default TTL

All transactions default to a TTL of 300 blocks (~15 hours). This prevents stale transactions from lingering indefinitely. Override with ttl: 0 for no expiration.

Querying an Oracle

typescript
import { queryOracle } from '@growae/reactive/actions'

const query = await queryOracle(config, {
  oracleId: 'ok_2dA...',
  query: 'What is the AE/USD price?',
})

console.log('Query ID:', query.id) // oq_...

Parameters

ParameterTypeDefaultDescription
oracleIdstringRequired. Oracle address (ok_...).
querystringRequired. The query string.
queryFeebigintoracle's feeFee to pay the oracle.
queryTtlType'delta' | 'block''delta'TTL type for the query.
queryTtlValuenumber10Query TTL value in blocks.
responseTtlType'delta' | 'block''delta'TTL type for the response.
responseTtlValuenumber10Response TTL value in blocks.
ttlnumber300Transaction TTL in blocks relative to current height. Set to 0 for no expiration.

Responding to a Query

typescript
import { respondToQuery } from '@growae/reactive/actions'

await respondToQuery(config, {
  oracleId: 'ok_2dA...',
  queryId: 'oq_abc...',
  response: '0.045 USD',
})

Parameters

ParameterTypeDefaultDescription
oracleIdstringRequired. Oracle address (ok_...).
queryIdstringRequired. Query ID (oq_...).
responsestringRequired. The response string.
responseTtlType'delta' | 'block''delta'TTL type for the response.
responseTtlValuenumber10Response TTL value in blocks.
ttlnumber300Transaction TTL in blocks relative to current height. Set to 0 for no expiration.

Extending an Oracle

typescript
import { extendOracle } from '@growae/reactive/actions'

await extendOracle(config, {
  oracleId: 'ok_2dA...',
  oracleTtlType: 'delta',
  oracleTtlValue: 500,
})

Parameters

ParameterTypeDefaultDescription
oracleIdstringRequired. Oracle address (ok_...).
oracleTtlType'delta' | 'block''delta'TTL type for extension.
oracleTtlValuenumber500Additional blocks.
ttlnumber300Transaction TTL in blocks relative to current height. Set to 0 for no expiration.