Skip to content

Instantly share code, notes, and snippets.

@dome
Created October 17, 2021 09:50
Show Gist options
  • Save dome/ed43639334a72249eeef23b773b7ac39 to your computer and use it in GitHub Desktop.
Save dome/ed43639334a72249eeef23b773b7ac39 to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.6;
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract ChainlinkOracle {
AggregatorV3Interface internal priceFeed;
/**
* Network: Kovan
* Aggregator: ETH/USD
* Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
*/
constructor(address _priceFeed) public {
priceFeed = AggregatorV3Interface(_priceFeed);
}
/**
* Returns the latest price
*/
function getLatestPrice() public view returns (int) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return price;
}
function getReferenceData(string memory _bases , string memory _quotes) public view returns (
int rate,
uint lastUpdatedBase,
uint lastUpdatedQuote
) {
(
uint80 roundID,
int price,
uint startedAt,
uint updatedAt,
uint80 answeredInRound
) = priceFeed.latestRoundData();
return (price, updatedAt, updatedAt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment