Getting Started with dAPIs
This is the getting started section for dAPIs along with some frequently asked questions. If you have a question that is not answered here, you can head over to our Discord server.
What are dAPIs?
dAPIs are on-chain decentralized data feeds sourced directly from first-party oracles owned and operated by API providers themselves (using Airnode) and are continuously updated using signed data. dApp owners can read the on-chain value of any dAPI in real-time.
dAPIs serve a variety of data feeds, such as latest cryptocurrency, stock, and commodity prices. They can power various decentralized applications such as DeFi lending, synthetic assets, stable coins, derivatives, NFTs, and more.
To read more about dAPIs, click here.
What is the API3 Market?
API3 Market enables users to browse, activate and manage dAPIs. Within the Market you can see all live dAPIs on the supported chains. You can also see the details of each dAPI, such as the provider, the asset type, the deviation threshold, the heartbeat, and the last on-chain updated price.
Check out the API3 Market here. You can browse through the available dAPIs and check out their details.
What are Managed dAPIs?
Managed dAPIs are sourced directly from multiple first-party data providers running an Airnode and aggregated using their Airnode's signed data. Unlike self-funded dAPIs, API3 manages the gas costs and the availability of the Managed dAPIs.
With Managed dAPIs, users get the option to configure the deviation threshold and heartbeat for each dAPI. The deviation threshold is the percentage deviation from the current value of the dAPI that triggers an update. If a dAPI is not updated within a known amount of time (called the heartbeat), the dAPI update is triggered.
Click here to read more about how to get started with Managed dAPIs.
What are Self-funded dAPIs?
Self-funded dAPIs are sourced directly from a single first-party data provider running an Airnode. The amount of gas you supply will determine how long your dAPI will be available for use. If you run out of gas, you can fund the dAPI again to keep it available for use. Unlike managed dAPIs, API3 does not manage the gas costs and the availability of the Self-funded dAPIs.
Self-funded dAPIs are only available at 1% deviation threshold and 24-hour heartbeat by default. You can update the deviation threshold and heartbeat by placing an order for a Managed dAPI.
Click here to read more about how to get started with Self-funded dAPIs.
How to use dAPIs in a smart contract?
To read a dAPI value in a smart contract, import the IProxy.sol
interface and call the read()
function. Here's an example:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import "@openzeppelin/contracts@4.9.5/access/Ownable.sol";
import "@api3/contracts/v0.8/interfaces/IProxy.sol";
contract DataFeedReaderExample is Ownable {
// The proxy contract address obtained from the API3 Market UI.
address public proxyAddress;
// Updating the proxy contract address is a security-critical
// action. In this example, only the owner is allowed to do so.
function setProxyAddress(address _proxyAddress) public onlyOwner {
proxyAddress = _proxyAddress;
}
function readDataFeed()
external
view
returns (int224 value, uint256 timestamp)
{
// Use the IProxy interface to read a dAPI via its
// proxy contract .
(value, timestamp) = IProxy(proxyAddress).read();
// If you have any assumptions about `value` and `timestamp`,
// make sure to validate them after reading from the proxy.
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
You'll have to set the proxyAddress
using the setProxyAddress()
function. You can get the proxyAddress
for activated dAPIs from within the data feed dashboard through the API3 Market.
To read more about reading a dAPI value, click here.
Data providers for managed dAPIs
There are nine providers used by managed dAPIs as a data source. These providers can be grouped by asset type(s) of supplied data:
- Coinpaprika
- dxFeed
- Finage
- Finnhub
- IEXCloud
- Kaiko
- NCFX
- Tradermade
- Twelvedata
Asset Type | Data Providers |
---|---|
Cryptocurrency | Coinpaprika, Finage, Twelvedata, NCFX, Kaiko, dxFeed |
Forex | Finage, Twelvedata, NCFX, IEXCloud, Finnhub, dxFeed, Tradermade |
Commodities | Finage, Twelvedata, dxFeed, Tradermade |
Equities | Finage, Twelvedata, IEXCloud, Finnhub, dxFeed |
Self-funded dAPIs
Self-funded dAPIs are single-sourced using Nodary as their data provider.
What are dAPI Proxy Contracts?
Each dAPI has a proxy contract that is used to read the value of the dAPI. The proxy contract is linked to a mapping that maps to a beaconId
or beaconSetId
. The beaconId
for each dAPI gets updated when the price hits the set deviation threshold/heartbeat using Airnode's Signed Data.
Read more about Proxy Contracts.
FLEX_END_TAG