API3 data feed reader example
An example project for reading API3 data feeds
Instructions
- Install dependencies
yarn
- Create a
.env
file similar toexample.env
echo 'MNEMONIC="bike north stone..."' > .env
- Browse market.api3.org and find a data feed you like
- Fund the data feed (unless it is already funded)
- Deploy the proxy to the data feed (unless it is already deployed)
- Copy the address of the proxy
- Deploy DataFeedReaderExample.
See the command below, but use your own
NETWORK
andPROXY
values. See the supported networks section for validNETWORK
values. See below for zkSync.
NETWORK=polygon-testnet PROXY=0x26690F9f17FdC26D419371315bc17950a0FC90eD yarn deploy
- Have DataFeedReaderExample read from the proxy.
See the command below, but use your own
NETWORK
value.
NETWORK=polygon-testnet yarn read-data-feed
Note about zkSync
This repo does not support deploying contracts on zkSync, which is why yarn deploy
will fail.
Instead, you can test the proxy by reading from it directly.
See the command below, but use your own NETWORK
and PROXY
values.
NETWORK=zksync-goerli-testnet PROXY=0x28ce555ee7a3daCdC305951974FcbA59F5BdF09b yarn read-direct
Supported networks
See https://github.com/api3dao/chains for details
- arbitrum-goerli-testnet
- arbitrum
- avalanche-testnet
- avalanche
- bsc-testnet
- bsc
- ethereum-goerli-testnet
- ethereum-sepolia-testnet
- ethereum
- fantom-testnet
- fantom
- gnosis-testnet
- gnosis
- moonbeam-testnet
- moonbeam
- moonriver
- optimism-goerli-testnet
- optimism
- polygon-testnet
- polygon-zkevm-goerli-testnet
- polygon-zkevm
- polygon
- zksync-goerli-testnet
Local development and testing
@api3/contracts
provides a MockProxy contract for local development testing.
See the tests for its usage, and run the tests with
yarn test
Advanced
Deploy a DapiProxy programmatically
Instructions have you use API3 Market to deploy a DapiProxy.
To do it programmatically, see the command below, but use your own NETWORK
and DAPI_NAME
values.
NETWORK=polygon-testnet DAPI_NAME=ETH/USD yarn deploy-dapi-proxy
You can see the valid dAPI names on API3 Market.
Deploy a DataFeedProxy programmatically
WARNING: DapiProxy reads a data feed whose composition is managed by API3, and using it is essentially outsourcing data feed curation to API3. DataFeedProxy reads a data feed whose composition is immutable, which is fully trust-minimized when used with first-party oracles. However, this also means when there is something wrong with the composition of the DataFeedProxy you are using, you will need to deploy a new one and switch to that, i.e., you will need to do your own data feed curation. Do not prefer DataFeedProxy over DapiProxy unless you understand the distinction and are capable of managing your own data feeds.
See the command below, but use your own NETWORK
and DATA_FEED_ID
values.
NETWORK=polygon-testnet DATA_FEED_ID=0x4385954e058fbe6b6a744f32a4f89d67aad099f8fb8b23e7ea8dd366ae88151d yarn deploy-data-feed-proxy
See https://github.com/nodaryio/examples for a more detailed example.
Update the proxy address of DataFeedReaderExample
You can update the proxy that your DataFeedReaderExample reads from.
- Follow the instructions
- Deploy a new proxy
- See the command below, but use your own
NETWORK
andPROXY
values
NETWORK=polygon-testnet PROXY=0xe5Cf15fED24942E656dBF75165aF1851C89F21B5 yarn update-proxy