Developers building on Polygon can now leverage Band's decentralized oracle infrastructure. With Band's oracle, they now have access to various cryptocurrency price data to integrate into their applications.
Currently, the list of supported symbols can be found at data.bandprotocol.com. Going forward, this list will continue to expand based on developer needs and community feedback.
The following methods can work with any combination of base/quote token pair, as long as the base and quote symbols are supported by the dataset.
Currently, there are two methods for developers to query prices from Band's oracle: through Band's
StdReference smart contract on Polygon and through their
Solidity Smart Contract
To query prices from Band's oracle, a smart contract should reference Band's StdReference contract, specifically the
getReferenceData takes two strings as the inputs, the base and quote symbol, respectively. It then queries the
StdReference contract for the latest rates for those two tokens, and returns a
ReferenceData struct, shown below.
getReferenceDataBulk instead takes two lists, one of the
base tokens, and one of the
quotes. It then proceeds to similarly queries the price for each base/quote pair at each index, and returns an array of
For example, if we call
['USD','ETH','BNB'], the returned
ReferenceData array will contain information regarding the pairs:
This contract demonstrates an example of using Band's
StdReference contract and the
Band's node helper library
bandchain.js also supports a similar
getReferenceData function. This function takes one argument, a list of token pairs to query the result of. It then returns a list of corresponding rate values.
The code below shows an example usage of the function
The corresponding result will then be similar to
For each pair, the following information will be returned:
pair: The base/quote symbol pair string
rate: The resulting rate of the given pair
updated: The timestamp at which the base and quote symbols was last updated on BandChain. For
USD, this will be the current timestamp
rawRate: This object consists of two parts.
BigIntvalue of the actual rate, multiplied by
decimalsis then the exponent by which
ratewas multiplied by to get