Intermediate

How to fetch price feeds using Band Oracle

This tutorial provides an introduction to using the Band Oracle to fetch price feeds in a JavaScript application or smart contract on the Harmony network. The tutorial includes instructions on how to clone and run the example code from the GitHub repository . The first scenario shows how to fetch price feeds in JavaScript application code using the BandChain.js library, and the second scenario covers how to use the data in an EVM smart contract on the Harmony network. The tutorial also includes a link to more detailed documentation on the Band Oracle and its usage on the Harmony network.

The repo contains examples on how to fetch price feeds using band oracle.

There are two scenarios:

  • Fetching price feed in your javascript application code

  • Fetching price feed in your smart contract

Requesting data using BandChain.js library

git clone https://github.com/harmony-one/band_oracle
cd band_oracle

yarn
node main.js

 

in main.js

 
const { Client } = require("@bandprotocol/bandchain.js");

// BandChain REST Endpoint
const endpoint = "https://api-gm-lb.bandchain.org";
const client = new Client(endpoint);

async function exampleGetReferenceData() {
  const rate = await client.getReferenceData(["ONE/USD"]);
  return rate;
}

(async () => {
  console.log(await exampleGetReferenceData());
})();

 

Using BandChain data in EVM Smart Contract in Harmony

git clone https://github.com/harmony-one/band_oracle
cd band_oracle

yarn
export PRIVATE_KEY=place your private key here
yarn hardhat run ./scripts/deploy.js

 

Contract’s been deployed and you can call getPrice or getMultiPrices to get actual prices. More details with code snippets are in

Band’s StdReference contract for testnet 0xE740092E081CA7491A46C8Aa0175446e962e2A08

Mainnet contract is coming soon…