Quick Start
Working example of Aeternity — Saynetwork Integration.
The contract should include Say API library file which can be fetched from the latest version of the github repo ⟶
For Testnet: (Currently: Basic Query Only)
Assign a variable with new value in Say.aes file downloaded from above:
OraclesManager
toct_YG4rZB2qtr7rW8DenybZpr1gNLASqvtJDKcV4Bn1ZcMUXu7ca
Simple Query
A request for data is called query. The Say.query
is a function included in Say.aes
Library file and called from developer’s smart contract. It expects 2 arguments.
- A URL with applied format ⟶
- Value of AE tokens to cover the oracle fee.
The query request consists of 3 arguments.
- First argument is a URL with applied format (
__
[Double Underscore] for pointing the property) - Second argument is if callback required. Set to
true
if you want response directly in your smart contract (Implementation is in progress, set false for now) - Third argument is base fee or oracle fee.
Say.query("https://api.therocktrading.com/api/ticker/BTCEUR__result[0]__volume", false, 10)
The function will return a unique hash in bytes32 format and can be use to retrieve results later from smart contracts.
The Query ID
Every time the function Say.query
is called, It returns a unique ID, Hereby refered to as Query ID, which depends from the number of previous requests and the address of the smart contract. The queryId identifies a specific query done to Say network and it is returned to the contract as a parameter of the callback transaction.
The queryId can be used as well to implement different behaviors in the smart contract functions. In particular the get the result of the unique query anytime from smart contract.
Example
include "Say.aes"
contract MyContract =
record state = {
query_id : string,
answer: option(string)
}
stateful entrypoint init() =
Say.setOracle("oracle_plain")
{query_id = "",
answer = None}
payable stateful entrypoint query() : string =
require(Say.getBaseFee() =< Call.value, "Insufficient fee")
let _id : string = Say.query("https://poloniex.com/public?command=returnTicker__BTC_BTS__id", false, Call.value)
put(state{query_id=_id})
_id
stateful entrypoint getAnswer() : option(string) =
Say.getAnswer(state.query_id)
stateful entrypoint useAnswer() : option(string) =
put(state{answer = Say.getAnswer(state.query_id)})
state.answer
public entrypoint getBaseFee() : int =
Say.getBaseFee()
Authenticity Proofs
(Coming Soon on Testnet and Mainnet compatible with Iris update)
Authenticity proofs are at the core of Say network oracle model. Smart contract can request authenticity proofs together with their data by calling the Say.setOracle("oracle_proof")
function available in the Say.aes library.
Available Proof Types are:
oracle_plain
: In this case proof type is NONE.oracle_proof
: Here the proof type is set to TLSNotary.
Setting oracle type to proof in this Example
stateful entrypoint init() =
Say.setOracle("oracle_proof")