Created
May 19, 2020 07:04
-
-
Save what-the-func/4a77858a973326dff57701a8f1b04ff0 to your computer and use it in GitHub Desktop.
Chainlink Aggregator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.0; | |
import "@chainlink/contracts/src/v0.6/dev/AggregatorInterface.sol"; | |
contract MyContract { | |
AggregatorInterface internal feed; | |
constructor(address _aggregator) public { | |
feed = AggregatorInterface(_aggregator); | |
} | |
function getLatestAnswer() public view returns (int256) { | |
return feed.latestAnswer(); | |
} | |
function getLatestTimestamp() public view returns (uint256) { | |
return feed.latestTimestamp(); | |
} | |
function getPreviousAnswer(uint256 _back) public view returns (int256) { | |
uint256 latest = ref.latestRound(); | |
require(_back <= latest, "Not enough history"); | |
return feed.getAnswer(latest - _back); | |
} | |
function getPreviousTimestamp(uint256 _back) public view returns (uint256) { | |
uint256 latest = ref.latestRound(); | |
require(_back <= latest, "Not enough history"); | |
return feed.getTimestamp(latest - _back); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working ETH/USD price feed contract on Rinkeby
0x0bF4e7bf3e1f6D6Dc29AA516A33134985cC3A5aA