Getting Started

You can use APRO Data Feeds to connect your smart contracts to asset pricing data. These data feeds aggregate information from many independent APRO node operators. Each price feed has an on-chain address and functions that enable contracts to read real-time pricing data directly from that address.

This section explains the Push Model, where APRO pushes real-time data to your contracts, allowing for immediate access to pricing updates without requiring frequent manual requests. This approach optimizes performance by reducing on-chain calls and enhances efficiency for applications that need continuous updates.

You'll learn how to read Data Feeds and store the value on-chain using Solidity. The code for reading Data Feeds on BitLayer or other EVM-compatible blockchains remains consistent across different chains and data feed types. You can choose various types of feeds depending on your use case, but the request and response format stays the same. However, the answer's decimal length and expected value ranges might differ depending on the feed you are using.

The contract has the following components:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import {AggregatorV3Interface} from "./AggregatorV3Interface.sol";

/**
 * THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED
 * VALUES FOR CLARITY.
 * THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
 * DO NOT USE THIS CODE IN PRODUCTION.
 */
 

contract DataConsumer {
    AggregatorV3Interface internal dataFeed;

    /**
     * Network: Bitlayer
     * Aggregator: BTC/USD
     * Address: 0x62d2c5dEe038FaEbc3F6ec498fD2Bbb3b0080B03
     */
    constructor() {
        dataFeed = AggregatorV3Interface(
            0x62d2c5dEe038FaEbc3F6ec498fD2Bbb3b0080B03
        );
    }

    /**
     * Returns the latest answer.
     */
    function getDataFeedLatestAnswer() public view returns (int) {
        // prettier-ignore
        (
        /* uint80 roundId */,
        int256 answer,
        /*uint256 startedAt*/,
        /*uint256 timeStamp*/,
        /*uint80 answeredInRound*/
        ) = dataFeed.latestRoundData();
        return answer;
    }

    /**
     * Returns decimals.
     */
    function getDecimals() public view returns (uint8) {
        uint8 decimals = dataFeed.decimals();
        return decimals;
    }
}

This example contract obtains the latest price answer from the BTC / USD feed on the Bitlayer testnet.

Last updated