Course Content

Chapter 0: Introduction


Chapter 1: Oracle script overview





Chapter 1

Oracle script overview

Estimated time: 12 mins


What is an oracle script?

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.

How does an oracle script work?

Below is an overview of how the data is retrieved when a data request to an oracle script is called Data Source Workflow

However, inside an Oracle script, it's workflow can be broken down into two main steps:

  • Preparation phase
  • Execution phase
Preparation phase

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.

Execution phase

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.

Quiz

What is the purpose of an oracle script's execution phase?

Previous Chapter

Introduction