Created
September 4, 2020 16:45
-
-
Save PatrickAlphaC/8f1132c1c3062203c774cd09e3a89b8e to your computer and use it in GitHub Desktop.
Kovan LTC/USD Price feed for Chainlink. Deploy using: https://remix.ethereum.org/#version=soljson-v0.6.7+commit.b8d736ae.js&optimize=false&evmVersion=null&gist=8f1132c1c3062203c774cd09e3a89b8e
This file contains hidden or 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
| /** 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