Course Content

Chapter 0: Introduction


Chapter 1: data script overview





Chapter 1

data script overview

Estimated time: 12 mins


What is a data script?

A data 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 a data 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 a data script work?

Below is an overview of how the price data is retrieved when making a data request to a data script. Data Source Workflow

However, inside a data script, its 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 data 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 function execute(), which should be defined in the data 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 data script's execution phase?

Previous Chapter

Introduction