๐ฅ Query Examples
This section provides practical examples of how to query the QIE Oracle from both JavaScript (frontend/backend using ethers.js) and Solidity (on-chain smart contracts). These examples help developers easily integrate the oracle into dApps and smart contracts.
๐จ Solidity Example
Use this example to read the latest price from the oracle inside a smart contract.
// 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;
}
}
Replace
oracleAddresswith the deployed address of the QIE Oracle contract on your network.
๐ฆ JavaScript Example (ethers.js)
Use this example in your frontend or backend to query the oracle using ethers.js.
โ ๏ธ Donโt forget to replace
0xYourOracleAddressandyour_rpc_urlwith the correct values for your deployment.
๐ Additional Query: Get Historical Data
You can also query a specific round by ID to fetch past data.
Solidity:
JavaScript:
๐งช Tip: Mocking in Local Development
For local testing, you can deploy your own instance of the AggregatorV3 contract and call updateAnswer(int256) to simulate real-world updates.
Last updated