I am currently trying to use the function getRoundData() from Chainlink within a contract of mine. The function expects the parameter roundID (uint80) when called. I am trying to implement a getHistoricalData() function, described in this tutorial:
https://docs.chain.link/docs/historical-price-data/
My question is: What is the roundID? Where do I find those IDs?
Here is some test code I wrote:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol';
contract TestContract {
AggregatorV3Interface internal priceFeed;
constructor() {
// PriceFeed on Kovan Test Net
priceFeed = AggregatorV3Interface(0x22B58f1EbEDfCA50feF632bD73368b2FdA96D541);
}
/**
* Returns historical price for a round id.
* roundId is NOT incremental. Not all roundIds are valid.
* You must know a valid roundId before consuming historical data.
*
* ROUNDID VALUES:
* InValid: 18446744073709562300
* Valid: 18446744073709562301
*
* @dev A timestamp with zero value means the round is not complete and should not be used.
*/
function getHistoricalPrice(uint80 roundId) public view returns (int256) {
(
,
int price,
,
uint timeStamp,
) = priceFeed.getRoundData(roundId);
require(timeStamp > 0, "Round not complete");
return price;
}
}
When I call the function with the roundID = 18446744073709562301, the following error-message pops up:
call to TestContract.getHistoricalPrice errored: VM execution error.
Reverted 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f4e6f20646174612070726573656e740000000000000000000000000000000000