How To Use Witnet Price Feeds
Last updated
Last updated
The preferred way to consume the Witnet-powered price feeds is through the Price Feeds Router.
This smart contract is deployed in all the supported chains and allows your own smart contracts and Web3 applications to get the latest price of any of the supported currency pairs by providing the identifier of the pair to a single Solidity method. This removes the need to know the actual contract addresses handling the price updates from the Witnet oracle.
Alternatively, the Price Feeds Router also lets you find out the actual address of the Price Feed contract that is currently serving a specific currency pair (if that pair is supported in your chain).
While all the supported currency pairs are automatically updated in a timely manner according to their different update conditions, you can always use the Price Feed contracts to trigger a new price update at any time, if willing to pay the required gas for that.
Check this out for different examples on how to read prices from the Price Feeds Router and the Price Feeds contracts:
Code ExamplesDifferent price feeds are updated with different periods or every time that certain conditions are met. You can find all the conditions for updating here:
Update ConditionsCurrency pairs are identified by a bytes32
value, calculated as the keccak256
hash of the currency pair caption. The caption is composed as the string concatenation of: Price-
, first asset denomination (e.g. BTC
), /
, second asset denomination (e.g. USD
), -
, and the number of decimals.
For the sake of simplicity, currency pairs served by the Witnet's Price Router can also be identified by just using the first 4 bytes (see ID4 below) of the full bytes32
identifier (ID32).
This table contains all the currency pairs that are currently being updated on a regular basis:
Caption | ID4 | ID32 |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
Clicking on any of the captions above will take you to the Javascript equivalent of the RADON script that is processed by the Witnet oracle on every single price update of the corresponding currency pair.
As introduced by the 2017 Witnet whitepaper, RADON is "a flow-based, tacit, point-free scripting language [...] implemented as a domain specific language (DSL), [... that] includes normalization and aggregation methods in a MapReduce style".
Basically, it specifies the math, filters, reducers and tally operator to apply to the values fetched from a set of given sources, as well as the witnessing thresholds and quality levels to be met by the Witnet oracle when solving the price update.