Oracles
Learn how to use oracle smart contracts to access external data sources when building an FVM dApp.
Obtain Price Feeds with the Tellor Oracle
contract PriceContract is UsingTellor {
uint256 public btcPrice;
//This Contract now has access to all functions in UsingTellor
constructor(address payable _tellorAddress) UsingTellor(_tellorAddress) {}
function setBtcPrice() public {
bytes memory _b = abi.encode("SpotPrice",abi.encode("btc","usd"));
bytes32 _queryId = keccak256(_b);
uint256 _timestamp;
bytes memory _value;
(_value, _timestamp) = getDataBefore(_queryId, block.timestamp - 15 minutes);
require(_timestamp > 0, "No data exists");
require(block.timestamp - _timestamp < 24 hours, "Data is too old");
btcPrice = abi.decode(_value,(uint256));
}
}Last updated