Solidity
Last updated
Last updated
There are two ways that you can access the oracle in your dApp. You can either declare an IDIAOracleV2 interface or import the solidity library.
The following is an example of how to retrieve price value from a standard DIA oracle. For the purpose of this example, we will be using the following demo oracle on Ethereum: .
Access any DIA oracle smart contract.
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.
The response of the call contains four values:
The current asset's price in USD with a fix-comma notation of 8 decimals.
The of the last oracle update.
Find the detailed description of the functions and how to run tests on our GitHub page:
DIA has a dedicated Solidity library to facilitate the integration of DIA oracles in your own contracts. The library consists of two functions, getPrice
and getPriceIfNotOlderThan
.
Returns the price of a specified asset along with the update timestamp.
Parameters:
oracle
address
Address of the oracle that we want to use
key
string
The asset that we want to use e.g. "ETH/USD"
Return Values:
latestPrice
uint128
Price of the specified asset returned by the DIAOracle
timestampOflatestPrice
uint128
The update timestamp of the latest price
Checks if the oracle price is older than maxTimePassed
Parameters:
oracle
address
Address of the oracle that we want to use
key
string
The asset that we want to use e.g. "ETH/USD"
maxTimePassed
uint128
The maximum acceptable time passed in seconds since the the price was updated
Return Values:
Price
uint128
Price of the specified asset returned by the DIAOracle
inTime
uint128
A boolian that is true
if the price was updated at most maxTimePassed seconds ago, otherwise false
Find a detailed integration example and how to run a test on our GitHub page: