> For the complete documentation index, see [llms.txt](https://qi-blockchain.gitbook.io/qie-oracle/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://qi-blockchain.gitbook.io/qie-oracle/developer-guide/example-fetching-btc-and-eth-prices-solidity.md).

# 🧾 Example: Fetching BTC & ETH Prices (Solidity)

Here’s a sample Solidity snippet showing how to fetch real-time prices for **BTC** and **ETH** using QIE Oracle contracts. These oracles are based on your custom implementation of `AggregatorV3`.

***

#### 🔍 Assumptions

* You have deployed two oracle contracts using your custom `AggregatorV3` contract:
  * One for BTC (e.g., BTC/USD)
  * One for ETH (e.g., ETH/USD)
* Both contracts implement `AggregatorV3Interface`
* The contract addresses are known and passed during deployment

***

#### 🧱 Sample Solidity Code

```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

contract AssetPriceConsumer {
    AggregatorV3Interface public btcOracle;
    AggregatorV3Interface public ethOracle;

    constructor(address _btcOracle, address _ethOracle) {
        btcOracle = AggregatorV3Interface(_btcOracle);
        ethOracle = AggregatorV3Interface(_ethOracle);
    }

    function getLatestBTCPrice() public view returns (int256) {
        (
            , 
            int256 price,
            , 
            , 
        ) = btcOracle.latestRoundData();
        return price;
    }

    function getLatestETHPrice() public view returns (int256) {
        (
            , 
            int256 price,
            , 
            , 
        ) = ethOracle.latestRoundData();
        return price;
    }
}

```

#### 🧪 Usage

This contract allows you to:

* Fetch the latest BTC/USD and ETH/USD prices
* Use the prices in further contract logic (e.g., swaps, comparisons, liquidations)

You can call:

```
getLatestBTCPrice(); // Returns the latest BTC price (int256)
getLatestETHPrice(); // Returns the latest ETH price (int256)

```

#### ⚠️ Notes

* Ensure that the oracle contracts are properly updated by the owner before use.
* The returned price is an `int256` and may include decimals (check `decimals()` from the oracle).
* If the oracle has not been updated yet, `latestRoundData()` will revert.

***

#### 📘 Bonus: Get Oracle Metadata

You can also fetch metadata like description and decimals:

```
function getBTCMetadata() public view returns (string memory, uint8) {
    return (btcOracle.description(), btcOracle.decimals());
}
```
