Icon-BandProtocol Integration

OpenDevICON
OpenDevICON
Published in
2 min readNov 12, 2020

Band Protocol is a cross-chain data oracle platform. It allows integration of real world data and APIs to smart contracts. It has recently been gaining prominence in the Oracle space due to its certain design and architecture choices. It is built using the Cosmos sdk and provides cross-chain using IBC. The Oracle Script architecture makes it easy for developers to create custom-made oracles using WebAssembly to connect smart contracts with traditional APIs.

Band Protocol is already integrated with the ICON platform. Developers on ICON can use the existing integration to get price feeds for ICON native assets such as ICX using the Band’s std_reference SCORE on ICON. More on this can be found here. Besides this developers can use any of the Oracle scripts or create custom scripts to provide custom Oracle data to their SCORE in ICON.

Let us explore how to integrate custom Oracle data for your SCORE.We will explore an example available via ODI here. In this example we are using Band’s Quantum Random Number Generator Oracle Script to get a random number from Band. That random number is then used to decide on the winning number for a dice roll for a user. It uses the Bridge contract cxc2685f4bde237b38b9fac77312402be7df715c34.

Please refer to the code on at https://github.com/OpenDevICON/bandprotocol-dice

This is just a simple example to showcase how one can get a random number from BandProtocol and set it to a SCORE in ICON. This is not a production ready app and should just be used to understand the moving parts.

The front end is integrated with the iconex wallet and users can place a bet and submit transactions using the iconex wallet. When the submit button is pressed it calls the callBet function which in turn submits a transaction to the Dice score calling its call_bet method. This in turn calls the get_random function to get a random number from another score RandomNumber.

This RandomNumber SCORE showcases the integration with BandProtocol.

This score has a set_number function which in turn calls a Bridge SCORE provided by the platform. Bridge score has a function relay_and_verify(proof) . This is the core of the Band Protocol mechanism that allows calling an oracle externally and still be able to pass and verify the result in the blockchain using Light Client Protocol. Please go through this Light Client Protocol to understand the details of proof mechanism that secures and validates the data obtained off chain from BandProtocol.

In our example , the backend script, interacts with BandProtocol and calls the Quantum Random Number Generator Oracle script. The result proof is sent to RandomNumber score’s set_number. This function in turn calls the relay_and_verify(proof) on the Bridge to validate the proof and get the request and return parameters. Return parameter has the random number that this then set in the score used by the Dice SCORE.

--

--