Loading...
pragma solidity ^0.8.3;
import "https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Kovan
* Aggregator: ETH/USD
* Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
*/
constructor() public {
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
}
/**
* Returns the latest price
*/
function getThePrice() public view returns (int) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return price;
}
}
Here the Address we have put inside constructor "0x9326BFA02ADD2366b30bacB125260Af641031331" is used for ETH/USD and that too for Kovan testnet.
You can find various addresses for various testnets from here
When you go for finding a suitable pair of address from the link given you can see their decimal values are also written i.e, when you get the output like 214139672966 actual value will be 2141.39672966 usd as we can see for the pair ETH/USD, the decimal value is 8.
For many more exciting tutorials keep following my username @BlockTalks_Raj
!!!!!HAPPY LEARNING!!!