Skip to main content

Introduction

When someone wants to request data from BandChain’s data, they do not interact or call the data sources directly. Instead, they call a data script, which then proceeds to execute the necessary data sources.

A data script's job, unlike a data source, is to be responsible for compiling the results from various data sources to enable on-chain security. As such, a data script, similarly to a smart contract on other platforms such as Ethereum, Near and Solana, is executed on-chain rather than off-chain.

img

Data Script Specification

At a basic level, an data script itself is just an executable program that encodes two pieces of data:

  • A set of raw data requests to the data sources it requires
  • A method of aggregating those the raw data reports from the requests sent into a final result

Data scripts themselves are Turing-complete and can be written in any programming language that supports compilation into WebAssembly code. This composability and Turing-completeness make data scripts very similar to smart contracts.

Data Script Execution Flow

img

  1. Preparation Phase During the preparation phase, the data script outlines the data sources that are required for its execution. It then sends out a request to BandChain’s validators to retrieve the result from the required data sources. The content of this request consists of the data sources’ execution steps and the parameters required by said data sources.
  2. Aggregation Phase During the aggregation phase, the data script aggregates all the data reports returned by the validators. Each report contains the values which the validator received from said data sources. The script then proceeds to combine those values into a single final result. Note that the specifics of the aggregation process is entirely up to the design of the data script. BandChain does not enforce any regulations regarding the aggregation method used and entirely leaves that design decision to the creator of the script. Instead of a typical plain medianizer, the data script can encode custom conditions such as a data deviation rule to ensure that all data points returned will stay within certain percentage deviation from each other and to revert the transaction if otherwise.

👉 For more information on data scripts and its execution, please refer to the corresponding page on our wiki.