Band Protocol – Decentralized Data Oracle for Web 3.0 Applications

Tram Ho

I. What is Band Protocol?

Blockchain applications using smart contracts are increasingly being applied in real fields, along with the demand for data posted on smart contracts. However, the current data is not completely guaranteed to be distributed as well as data security issues. Therefore, Band Protocol is built towards becoming a decentralized oracle for dApps on many blockchain networks by ensuring maximum security, speed and low cost.

II. Why use Band Protocol?

1. Problems of current systems

Although building oracle data to bring data to smart contracts is not a new problem, current applications have not solved some outstanding issues such as:

  • Architecture is not completely decentralized.
  • Development and application are still difficult.
  • There is no financial policy to encourage data providers.

2. Why use Band protocol

Most smart contract platforms currently lack access to real data, which limits the capabilities of smart contracts.

Band Protocol was developed to aim at building an oracle infrastructure that supports multiple blockchain platforms while expanding the applicability of smart contracts. The project helps to connect public blockchains with offchain information, with the following design criteria:

  • Speed ​​and scalability : The system must be able to accommodate a large number of data requests for multiple public block chains with minimal latency.
  • Crosschain compatibility: The system can serve data for all available public blockchains.
  • Flexible data provision : Supports a variety of ways to retrieve and aggregate data.

III. Decentralized data delivery network (D3N)

D3N is a blockchain of Band protocol, with native token is Band. Built on Tendermint and Cosmos SDK, D3N uses the BFT consensus algorithm to receive instant confirmation when enough block validators are available. Besides signing blocks, validators also play the role of responding to the data requests sent to the system.

Some concepts

To learn more about D3N, we have to understand some of the following concepts:

Data Sources

Data Sources : a basic unit of an oracle system, describing the process of obtaining raw data from the source and related costs in a query. In D3N, data source is registered on the system with 2 types:

  • Owned data source: can be changed, upgraded and charged by the owner.
  • Unowned data source: immutable and constant.

Note: Although unowned is unchanged, data may still be dominated by a centralized party if the data source is concentrated.

Data source example takes coin price from coingecko.

Oracle Scripts

Oracle script : is a program to encode raw data to send to the necessary data source and describe how to synthesize the output data

An example illustrating an oracle script that retrieves coin price data from various sources: CoinGecko, CryptoCompare, and CoinMarketCap.

Data Requests

A data request is a transaction from a user to make data queries based on an oracle script. A transaction requires data to specify an oracle script to execute, script parameters, and other security parameters.

Raw Data Reports

The raw data report results from resolving raw data requests with the D3N block validators. The raw data report is sent to D3N. When enough reports are collected, they will be used in the second phase of the oracle script to calculate the final outcome of the raw data request.

Oracle Data Proof

When the summary is complete, the final result of the data request is permanently stored in the global state of D3N. Like most blockchains, the entire state of D3N can be represented as a Merkle root hash. Oracle Data Proof is merkle proof that the existence of the final result of the data request with other information related to it, including oracle script hash, parameters, execution time, etc.

Data Request Lifecycle

  1. Users send data requests to the network by broadcasting MsgRequestData. The message includes the oracle script it wants to call and other additional parameters.
  2. Once the transaction is confirmed, the prepare function of the oracle script will be run in a decentralized manner. This function will generate the set of raw data requests needed to continue executing the oracle script.
  3. The Block validator D3N checks the data requests and executes the corresponding data sources
  4. Block validator sends data reports to the network by broadcasting MsgReportData. Data reports are temporarily stored on the blockchain.
  5. When enough block validators send data (as specified in the data request’s security parametes). D3N continues to execute oracle scripts to aggregate data that returns the final result, and is saved to the blockchain permanently.
  6. The final result will be available on the state tree of the blockchain. Data can be sent to other block chains via communication between D3N’s blockchains.

IV. Application

Band Protocol allows users to retrieve data via web api and use them on the blockchain. Developers can access data via Bandchain – a cosmos-based blockchain suitable for oracle requests and payments, and can also use dApps via interchain communication. The integration of oracle data is done through 3 basic steps:

  • Select oracle script
  • Request data from Bandchain
  • Use data on smart contracts

The blockchain is being supported by the Band protocol ( https://docs.bandchain.org/dapp-developers/getting-started )

B1: Select Oracle script

BandChain supports the following scripts:

B2: Request BandChain Data

There are 2 ways to request data from the D3N blockchain:

  • Through Explorer
  • Through the Rest API

Request data through Explorer

Go to http://scan.alpha.bandchain.org/ and click Oracle Script in the right corner of the screen.

Select Oracle Script There are many oracle for us to choose from. Here we will explore oracle binance_price

Send request

Select the execute tab, select the type of token to be priced and press send request. The result is a transaction.

Get results

Inside are transaction data such as transactionID, block, parameter, return time data. To use the above result in smart contract. We use the Proof of Validity tab and copy the result in there.

Request data via API

In dApp, we cannot use explorer. Therefore, the Band protocol provides a Rest API to make data retrieval more convenient and simple. The method used is POST, the body of the request sent as json

Response:

B3: Use data in smart contracts

After obtaining the data, we will write a smart contract for our Dapp. In this example, we will write the contract to get BTC / USD data:

Let’s analyze each part of the above contract

The first is to import BandChainLib and IBridge from the bandchain-helper-library package.

Declaring the state of the contract

The codeHash, params and bridge parameters to confirm the correct data are requested and sent from BandChain. These 3 parameters are passed to the constructor:

  • codeHash is the hash of Oracle Script. Binance scripthash example: Script Hash: 0x6b7be61b150aec5eb853afb3b53e41438959554580d31259a1095e51645bcd28
  • Params is the serialized string of parameters for the Oracle Script request
  • bridge is the bridge contract deployed for the blockchain

Define update function

Report price is the data we received from step 2. However, the data is being stored in bytes so we have to decode the given data. Use the IBridge.relayAndVerify function

The last is data updates

Oke. So we have an example of smart contract using BandChain oracle data.

Hope this article helped you in developing your smartcontract and Dapp. See you in the following articles with other platforms!

V. Source:

https://docs.bandchain.org/

Share the news now

Source : Viblo