Skip to content

Instantly share code, notes, and snippets.

@PatrickAlphaC
Created September 4, 2020 16:45
Show Gist options
  • Save PatrickAlphaC/8f1132c1c3062203c774cd09e3a89b8e to your computer and use it in GitHub Desktop.
Save PatrickAlphaC/8f1132c1c3062203c774cd09e3a89b8e to your computer and use it in GitHub Desktop.
/** This example code is designed to quickly deploy an example contract using Remix.
* If you have never used Remix, try our example walkthrough: https://docs.chain.link/docs/example-walkthrough
* You will need testnet ETH and LINK.
* - Kovan ETH faucet: https://faucet.kovan.network/
* - Kovan LINK faucet: https://kovan.chain.link/
*/
pragma solidity ^0.6.7;
import "https://github.com/smartcontractkit/chainlink/blob/master/evm-contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
contract HistoricalPriceConsumerV3 {
AggregatorV3Interface internal priceFeed;
/**
* Network: Kovan
* Aggregator: LTC/USD
* Address: 0xCeE03CF92C7fFC1Bad8EAA572d69a4b61b6D4640
*/
constructor() public {
priceFeed = AggregatorV3Interface(0xCeE03CF92C7fFC1Bad8EAA572d69a4b61b6D4640);
}
/**
* Returns the latest price
*/
function getHistoricalPrice(uint80 roundsBack) public view returns (int256) {
(uint80 roundId,,,,) = priceFeed.latestRoundData();
uint80 historicalRoundId = roundId - roundsBack;
(
uint80 id,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = priceFeed.getRoundData(historicalRoundId);
return price;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment