๐Ÿ“ก Reading Data from Oracle

Once connected, you can query Oracle contracts to fetch live prices.

Example: Fetch BTC Price

interface IQIEOracle {
    function getPrice(string calldata asset) external view returns (uint256);
}

contract FetchPriceExample {
    IQIEOracle oracle = IQIEOracle(0x9E596d809a20A272c788726f592c0d1629755440); // BTC Oracle

    function getBTCPrice() public view returns (uint256) {
        return oracle.getPrice("BTC"); // Returns BTC price in smallest unit
    }
}

JavaScript Example (ethers.js)

const { ethers } = require("ethers");
const provider = new ethers.JsonRpcProvider("https://rpc.qiechain.io");

const oracleAddress = "0x9E596d809a20A272c788726f592c0d1629755440";
const oracleAbi = ["function getPrice(string asset) view returns (uint256)"];

const oracleContract = new ethers.Contract(oracleAddress, oracleAbi, provider);

async function fetchBTCPrice() {
    const price = await oracleContract.getPrice("BTC");
    console.log("BTC Price:", price.toString());
}

fetchBTCPrice();

โšก Tip: Replace "BTC" with "ETH", "XRP", or any supported asset symbol to fetch other prices.

This section provides the foundation for developers to start interacting with QIE Oracle immediately, whether through smart contracts or scripts.

Last updated