Last updated
Last updated
The Price Router contract is the easiest and most convenient way to consume Witnet price feeds on any of the .
To read price values from the Price Router contract, you need first to identify the WitnetPriceRouter
address specific to the chain in which you plan to deploy your contracts:
The example below shows how to read the price of two different assets from the Witnet Price Router:
As Solidity does not support float
types, all prices are provided as int256
values, with a fixed number of decimals digits.
For instance, if the BTC/USD price is $41,847.762289, the Price Router contract will give 41847762289
for the currency pair identified as "Price-BTC/USD-6"
.
You may also read the latest price of any of the supported currency pairs from your Web3 application by interacting directly with the Price Router contract:
The WitnetPriceRouter
contract offers a series of methods that can be used to list the currency pairs that are currently maintained by the Witnet Foundation, as well as their human-readable captions, and the Price Feed contracts currently serving updates for each one of them:
When interacting with a IWitnetPriceFeed contract, you can get not only the last valid price value (and timestamp) solved by the Witnet oracle, but also the hash of the transaction within the Witnet's sidechain that triggered that last valid update request. This Witnet transaction hash can be used as a means to verify and track the whole resolution process that took in place within the Witnet oracle's sidechain.
Moreover, you can also detect whether there is a recent price update pending to be solved, or if the latest update attempt could not get solved for whatever reason.
First, get from the WitnetPriceRouter
contract the IWitnetPriceFeed
address that is currently serving price updates on any given currency pair.
Then, just call the requestUpdate() payable
method.