Skip to main content

Using DIAOracleV2 Interface

The following is an example of how to retrieve price value from a standard DIA price oracle. For the purpose of this example, we will be using the following demo oracle on Ethereum: 0xCD5F…f3cB.
1
Access any DIA price oracle smart contract.
2
Call getValue(pair_name) with pair_name being the full pair name such as BTC/USD. You can use the “Read” section on Etherscan to execute this call.
3
The response of the call contains 2 values:
  1. The current asset’s price in USD with a fix-comma notation of 8 decimals.
  2. The UNIX timestamp of the last oracle update.
Always check the returned timestamp before using the price. DIA oracles do not revert on old data. Use getPriceIfNotOlderThan below, or see Check Price Freshness.
Find the detailed description of the functions and how to run tests on our GitHub page:

GitHub - diadata-org/DIA-integration-sample

Solidity integration example

Using Solidity Library

DIA has a dedicated Solidity library to facilitate the integration of DIA price oracles in your own contracts. The library consists of two functions, getPrice and getPriceIfNotOlderThan.

Access the library

Methods

getPrice

Returns the price of a specified asset along with the update timestamp. Parameters: Return Values:

getPriceIfNotOlderThan

Checks if the oracle price is older than maxTimePassed Parameters: Return Values: Find a detailed integration example and how to run a test on our GitHub page:

GitHub - diadata-org/DIAOracleLib

Sample contract