Oracles
Introduction
1. Oracle: register
import { AeSdk, Oracle } from '@aeternity/aepp-sdk'
// init an instance of the SDK using the AeSdk class
const aeSdk = new AeSdk({ ... })
// it should be an instance of AccountBase with non-zero balance
const oracleAccount = new AccountMemory(...)
const oracle = new Oracle(oracleAccount, aeSdk.getContext())// set TTL with a delta of 1000 blocks
const oracleTtlOptions = { oracleTtlType: ORACLE_TTL_TYPES.delta, oracleTtlValue: 1000 };
// OR set a specific block height to expire
const oracleTtlOptions = { oracleTtlType: ORACLE_TTL_TYPES.block, oracleTtlValue: 555555 };
// queryFee is optional and defaults to 0
// oracleTtlValue is optional and defaults to 500
// oracleTtlType is optional and defaults to ORACLE_TTL_TYPES.delta
const options = { queryFee: 1337, ...oracleTtlOptions };
// the first argument is the queryFormat and the second is the responseFormat
await oracle.register('{"city": "str"}', '{"temperature": "int"}', options);2. Some party: query an oracle and poll for response
Query (preferred)
Post query (alternative)
Poll for response (alternative)
3. Oracle: poll for queries and respond
Handle queries (preferred)
Poll for queries (alternative)
Respond to query (alternative)
4. Oracle: extend
5. Get the current state from the node
Example applications
Last updated
Was this helpful?