Access the Oracle
This page contains an overview over how to access crypto asset information using the DIA oracle system
How to access DIA's oracle?
Here 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: 0xa935...5856.
Access any DIA oracle smart contract.
Call
getValue(pair_name)
withpair_name
being the full pair name such asBTC/USD
. You can use the "Read" section on Etherscan to execute this call.The response of the call contains four values:
The current asset price in USD with a fix-comma notation of 8 decimals.
The UNIX timestamp of the last oracle update.
The oracle exists on various blockchains and contains information about crypto assets. You can access a price quotation (see sources and methodology) and the current circulating supply as well as the timestamp of the last update.
See DIA's oracle structure for more information:
Oracle structuresOracle integration example
You can find DIA's oracle integration samples in Solidity and Vyper languages for the EVM based chains.
Solidity
Here is an example on how you can integrate DIA's oracle into your smart contract with Solidity:
Find the detailed description of the functions and how to run tests on our GitHub page:
Vyper
Here is an example on how you can integrate DIA's oracle into your smart contract with Vyper:
Find the detailed description of the functions and how to run tests on our GitHub page
Accessing DIA's oracles with a dedicated Solidity library
DIA has a dedicated Solidity library to facilitate integration of DIA oracles in your own contracts. The library consists of two functions, getPrice
and getPriceIfNotOlderThan
.
Access the library
getPrice
Returns the price of a specified asset.
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:
Price
uint128
Price of the specified asset returned by the DIAOracle
getPriceIfNotOlderThan
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 test on our GitHub page:
Accessing 3rd party data oracles
The oracle contains information about price quotations of crypto assets from CoinMarketCap and Coingecko. You can access quotations for the top 50 assets ranked by market capitalization. You can execute an oracle call as follows:
Access DIA's guest quotation oracles (find them here).
Call
getValue(key)
wherekey
is the symbol for the asset in capital letters, for instanceBTC
for Bitcoin. You can use the "Read" section on Etherscan to execute this call.The response of the call contains two values:
The current asset price in USD.
The UNIX timestamp of the last oracle update.
You can find out more about 3rd party data here:
3rd Party Data AggregationSolidity DIA Oracles Integration Library
DIA has a dedicated library for Solidity developers to facilitate your integration journey.
Below is a sample function that allows to quote Asset Price from any of the DIA's oracles