📥 Query Examples
🟨 Solidity Example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract PriceConsumer {
AggregatorV3Interface public priceFeed;
constructor(address oracleAddress) {
priceFeed = AggregatorV3Interface(oracleAddress);
}
function getLatestPrice() public view returns (int256) {
(
, // roundId
int256 price,
, // startedAt
, // updatedAt
// answeredInRound
) = priceFeed.latestRoundData();
return price;
}
}
🟦 JavaScript Example (ethers.js)
📌 Additional Query: Get Historical Data
🧪 Tip: Mocking in Local Development
Last updated