๐Ÿ“ฅ 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 oracleAddress with 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 0xYourOracleAddress and your_rpc_url with 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