This project demonstrates how to get price feeds for different currencies using Chainlink Data Feed and Chainlink Feed Registry. We will learn how to use both of these either in a smart contract or in a DApp.
- Install dependencies using
yarn
- Create a
.env
in the project directory and write the following environment variables.AGGREGATOR
environment variable is for BTC / USD price feed on Rinkeby Network.
MNEMONIC = REPLACE_WITH_YOUR_MNEMONIC
RINKEBY_RPC = https://rinkeby.infura.io/v3/YOUR_INFURA_PROJECT_ID
# Aggregator address for BTC / USD feed on Rinkeby network.
# See for details: https://docs.chain.link/docs/ethereum-addresses/#Rinkeby%20Testnet
AGGREGATOR = 0xECe365B379E1dD183B20fc5f022230C044d51404
- Deploy the smart contract
contracts/DataFeedConsumer.sol
using the script inscripts/deployDataFeedConsumer.ts
. Make sure you have some Rinkeby test ETH in your account you are using to deploy the contract.
npx hardhat run scripts/deployDataFeedConsumer.ts --network rinkeby
After deployment, save the address of the deployed DataFeedConsumer
in .env
file.
DATA_FEED_CONSUMER = 0xB674c51096a21d3E36c12F2c76Ba4b9bd306C4b9
- To get the latest
BTC / USD
price feed through theDataFeedConsumer
smart contract, run the script inscripts/withDataFeedSolidity.ts
.
npx hardhat run scripts/withDataFeedSolidity.ts --network rinkeby
- To get the latest
BTC / USD
price feed throughEthers
library, run the script inscripts/withDataFeedJavaScript.ts
. This is how you will use Chainlink Data Feed in a DApp usingEthers
.
npx hardhat run scripts/withDataFeedJavaScript.ts --network rinkeby
- Install dependencies if you haven't already.
yarn
- In
.env
file, write the following environment variables.FEED_REGISTRY
environment variable is for Feed Registry on Kovan Network.
MNEMONIC = REPLACE_WITH_YOUR_MNEMONIC
KOVAN_RPC = https://kovan.infura.io/v3/YOUR_INFURA_PROJECT_ID
# Feed Registry contract address for Kovan network.
# See for details: https://docs.chain.link/docs/feed-registry/#contract-addresses
FEED_REGISTRY = 0xAa7F6f7f507457a1EE157fE97F6c7DB2BEec5cD0
- Deploy the smart contract
contracts/FeedRegistryConsumer.sol
using the script inscripts/deployFeedRegistryConsumer.ts
. Make sure you have some Kovan test ETH in your account you are using to deploy the contract.
npx hardhat run scripts/deployFeedRegistryConsumer.ts --network kovan
After deployment, save the address of the deployed FeedRegistryConsumer
in .env
file.
FEED_REGISTRY_CONSUMER = 0xf756e9C157c44AFdabfDfe975Ca49944c5281a1D
- To get the latest
ETH / USD
price feed through theFeedRegistryConsumer
smart contract, run the script inscripts/withFeedRegistrySolidity.ts
.
npx hardhat run scripts/withFeedRegistrySolidity.ts --network kovan
- To get the latest
ETH / USD
price feed throughEthers
library, run the script inscripts/withFeedRegistryJavaScript.ts
. This is how you will use Chainlink Feed Registry in a DApp usingEthers
.
npx hardhat run scripts/withFeedRegistryJavaScript.ts --network kovan