# BandChain Course
# Introduction
## Who is this course for?
This course is designed for anyone who is interested in learning what BandChain is and how it works at a higher level.
## Course structure
### Chapter 1 - What is BandChain
In this section, you'll learn about what BandChain is.
### Chapter 2 - Why the need for BandChain
In this section, you'll learn why BandChain was made and what BandChain's usecases are.
### Chapter 3 - How does BandChain work?
In this section, you'll learn how BandChain's oracle works.
## Course objective
At the end of this course, you'll be able to:
- Under what BandChain's use cases are
- Have a high level understanding on how BandChain works
# Chapter 1 - What is BandChain
BandChain is a high-performance public blockchain build for data oracles using Cosmos-SDK that allows anyone to make a request for APIs and services available on the traditional web.
BandChain is designed to modularize and offload the heavy and resource-intensive tasks, such as fetching data from external sources, from a smart contract platform onto itself to prevent such tasks from congesting or causing high transaction fees on the destination network.
BandChain allows developers to query a wide range of data types. From on-chain data such as token balances and transaction data to off-chain data such asset prices, sports scores, flight statuses and weather conditions. If the data is available on the web, BandChain is essentially able to retrieve it.

<!-- questionaire
What is BandChain?
a. A smart contract platform
b. A private blockchain
c. A data oracle blockchain [ANSWER]
d. An off-chain API requester
-->
# Chapter 2 - Why the need for BandChain
While the majority of existing smart contract platforms support trustless executions of arbitrary programs, they lack access to real-world data. This limitation hinders the potential of the applications that are developed on those platforms.
BandChain solves this important issue by connecting public blockchains to real-world, off-chain information. The project was created with the following design goals:
## Speed and Scalability
The system must be able to serve a large quantity of data to multiple public blockchains with minimal latency, while maintaining a high throughput. The expected response time must be in the order of seconds.
## Cross-Chain Compatibility
The system must be blockchain-agnostic and able to serve data to most publicly available blockchains. Verification of data authenticity on the target blockchains must be efficient and trustless by nature.
## Data Flexibility
The system must be generic and able to support different methods of retrieiving and aggregating data, including both permissionless, publicly available data as well as information guarded by centralized parties.
BandChain achieves the aforementioned goals with a blockchain specifically built for off-chain data curation. The blockchain supports generic data requests and on-chain aggregation with WebAssembly-powered oracle scripts. Oracle results on BandChain blockchain can be sent across to other blockchains via the Inter-Blockchain Communication protocol (IBC) or through customized one-way bridges with minimal latency.
<!-- questionaire
BandChain solves what issue?
a. Providing smart contracts with access to real world data [ANSWER]
b. Allows for smart contracts to be trustlessly executed
c. Provides IBC services for other blockchains
d. Decentralizes centralized data
-->
# Chapter 3 - How does BandChain work?
## Yoda
Yoda is a program that BandChain's validator node use to fulfill data requests when they're selected to do so.
Yoda's main job is to listen for incoming oracle requests on BandChain and to execute the corresponding data sources listed within the oracle request. Once the data source is executed and it's results recieved and parsed, the end-results are then collated and packaged into a [`MsgReportData`](https://docs.bandchain.org/whitepaper/protocol-messages.html#msgreportdata), stored in a local pending list then broadcasted onto BandChain.

## Data Sources
A data source is the most fundamental unit in BandChain’s oracle system. It describes a proceduce, like a Python script, to retrieve and process a raw data point from a external source.
Anyone is able to deploy and register a data source on BandChain through sending a `MsgCreateDataSource` message to BandChain and if an owner is specified, the owner is able to edit a data source through sending a `MsgEditDataSource` message to BandChain.
## Oracle Scripts
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.
Similarly to a data source, anyone is able to deploy or edit an oracle script on BandChain through sending a `MsgCreateOracleScript` or `MsgEditDataSource` message to BandChain.
### Prepare Phase
During the preperation phase, an oracle script is used to request external data from validators through yoda.
### Execution Phase
During the execution phase, an oracle script processes the reported data from the validators and returns the output. The processing an oracle script can be done in a variety of ways but a common approach is to medianize the results.
## Data Request Flow
1. When requesting an oracle script, a [`MsgRequestData`](https://docs.bandchain.org/whitepaper/protocol-messages.html#msgrequestdata) needs to be broadcasted in a transaction to BandChain.
2. Once the transaction has been discovered on-chain, the randomly selected validators will then run the oracle scripts prepare code.
3. The prepare code sends a request to Yoda, which will execute the associated data sources and create a [`MsgReportData`](https://docs.bandchain.org/whitepaper/protocol-messages.html#msgreportdata) containing the data sources results.
4. The `MsgReportData` is then broadcasted in a message signed by the validator and broadcasted.
5. Once the transaction containing the `MsgReportData` is delivered, the reports are then checked to assure that the minimum number of validators have reported the data and once that is assured, the request is added to the [`PendingResolveList`](https://docs.bandchain.org/client-library/protocol-buffers/oracle-module.html#pendingresolvelist).
6. At the end of the block, the oracle script execute code is then run and its results saved on-chain.

<!-- questionaire
In order to request data on BandChain, what type of message must be sent within a transaction?
a. `MsgOracleResponse`
b. `MsgReportData`
c. `MsgRequestData` [ANSWER]
d. `MsgAddReporter`
-->
# Chapter 4 - Conclusion
Now that you've understood the basics of BandChain, we recommend you learn about BandChains data sources and how to create one to request data!