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

Tellor is an Oracle solution that enables price and Filecoin network data feeds for FVM dApps. To see important disclaimers about the use of Tellor, please review the Tellor Documentation, the Tellor Contract Reference, and this tutorial.

Ingredients

Instructions

  1. Inherit the UsingTellor contract in your code. An example, pulled from the sample project for UsingTellor, is shown just below.

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));
  }
}
  1. Pass the Tellor address as a constructor argument.

Oracle contract address (on both Calibration Testnet and Mainnet): 0xb2CB696fE5244fB9004877e58dcB680cB86Ba444

To see additional addresses for Tellor Oracles, please see this doc.

Last updated