Price Feed API Reference

When you use price feed, retrieve the feeds through the AggregatorV3Interface and the proxy address.

AggregatorV3Interface

Import this interface to your contract and use it to run functions in the proxy contract. Create the interface object by pointing to the proxy address. For example, on Bitlayer you could create the interface object in the constructor of your contract using the following example:

/**
 * Network: Bitlayer
 * Data Feed: BTC/USD
 * Address: 0x62d2c5dEe038FaEbc3F6ec498fD2Bbb3b0080B03
 */
constructor() {
  priceFeed = AggregatorV3Interface(0x62d2c5dEe038FaEbc3F6ec498fD2Bbb3b0080B03);
}
// SPDX-License-Identifier: MIT
pragma solidity >0.8.0;


interface AggregatorV3Interface {

  function decimals() external view returns (uint8);
  function description() external view returns (string memory);
  function version() external view returns (uint256);

  // getRoundData and latestRoundData should both raise "No data present"
  // if they do not have data to report, instead of returning unset values
  // which could be misinterpreted as actual reported values.
  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

}

Functions in AggregatorV3Interface

decimals

Get the number of decimals present in the response value.

function decimals() external view returns (uint8);
  • RETURN: The number of decimals.

description

Get the description of the underlying aggregator that the proxy points to.

function description() external view returns (string memory);
  • RETURN: The description of the underlying aggregator.

getRoundData

Get data about a specific round, using the roundId.

function getRoundData(
  uint80 _roundId
) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

Parameters:

  • _roundId: The round Id

Return values:

  • roundId: The round Id

  • answer: The answer for this round

  • 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

version

The version representing the type of aggregator the proxy points to.

function version() external view returns (uint256)
  • RETURN: The version number.