Getting Started
// 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;
}
}