Suppose that in my solidity contract, I need to see the price of ETH in terms of USD at a specific time, say on January 1, 2021. I would like to use the Historical Price Data Feed from chainlink (URL below). I imagine that to achieve this, I would have to pass the
roundId as a parameter when calling the outermost function, so that the contract can verify that this
roundId indeed gives the price corresponding to the timestamp of January 1, 2021. I am happy with this construction. However, I do not entirely understand the data given back. How do I verify that the
roundId indeed corresponds to the timestamp of interest?
URL to the documentation: https://docs.chain.link/docs/historical-price-data/
function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound )
Chainlink explanation with these return arguments:
- roundId: The round ID.
- answer: The price.
- startedAt: Timestamp of when the round started.
- updatedAt: Timestamp of when the round was updated.
- answeredInRound: The round ID of the round in which the answer was computed.