Chapter 1
Estimated time: 12 mins
An oracle script is a turing-complete executable program that is at the heart of BandChain. It encodes a set of raw data requests, which is then sent to the data sources, and aggregates the raw data returned from the data sources into a final report.
When an oracle script is called and executed, a data proof is also produced. This proof is a Merkle proof that shows the existence of the final result of the data request on BandChain. In addition to the actual result of the request, the proof also contains information on the request parameters such as the script hash, the time of execution and the number of validators that responded. This proof can then be used by any smart contract on other blockchains to verify that the existence of the data on BandChain and to retrieve the results stored.
Below is an overview of how the data is retrieved when a data request to an oracle script is called
However, inside an Oracle script, it's workflow can be broken down into two main steps:
During the preparation phase, a function prepare()
, which should be defined in the oracle script will be called.
This function should contain the logic to determine which data sources are required for its execution. It should also implement an Oracle Environment Interface(OEI) to communicate with BandChain to send out a request to BandChain's validators to retrieve the results from the required data sources.
During the execution phase, a functionexecute()
, which should be defined in the oracle script will be called.
This function can contain any set of logic to determine what to do with the data that was requested during the preparation phase and needs to return an output that will be packaged and sent back to BandChain.