Band Protocol
How to Interact with BandChain from Harmony Smart Contracts
Requesting data using BandChain.js library
const BandChain = require('@bandprotocol/bandchain.js');
const { Obi } = require('@bandprotocol/obi.js');//BandChain POA mainnet endpoint URL
//const endpoint = 'http://poa-api.bandchain.org';
//BandChain dev-net endpoint URL
const endpoint = 'http://guanyu-devnet.bandchain.org/rest';const getBTCPrice = async () => {
// Instantiating BandChain with REST endpoint
const bandchain = new BandChain(endpoint);// Create an instance of OracleScript with the script ID
const oracleScript = await bandchain.getOracleScript(76);// Create a new request, which will block until the tx is confirmed
try {
const minCount = 3;
const askCount = 4;
const mnemonic =
'panther winner rain empower olympic attract find satoshi meadow panda job ten urge warfare piece walnut help jump usage vicious neither shallow mule laundry';
const requestId = await bandchain.submitRequestTx(
oracleScript,
{
symbol: 'BTC',
},
{ minCount, askCount },
mnemonic
);
// Get final result (blocking until the reports & aggregations are finished)
const finalResult = await bandchain.getRequestResult(requestId);
let result = new Obi(oracleScript.schema).decodeOutput(
Buffer.from(finalResult.response_packet_data.result, 'base64')
);
console.log('RequestID: ' + requestId);
console.log(result);
} catch {
console.error('Data request failed');
}
};getBTCPrice();Using BandChain data in EVM Smart Contract in Harmony
Obi.sol
Decoders.sol
IBridgeCache.sol
Contract Constructor
getPrice Function
References:
Examples
Requesting data using BandChain.js library
Using BandChain data in EVM Smart Contract in Harmony
Last updated
Was this helpful?