# Getting Started

> Learn how to consume FTSOv2 feeds on Flare using an onchain Solidity contract.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.

Source: https://dev.flare.network/ftso/getting-started

You can use FTSOv2 to connect your smart contracts with real-world data feeds. FTSOv2 leverages Flare's network of 100 independent data providers to fetch offchain data and deliver it onchain. This section demonstrates how to consume FTSOv2's block-latency feeds on Flare using an onchain Solidity contract.

New to smart contract development?

Learn how to [deploy your first smart contract](/network/getting-started) before you start this guide.

## Sample contract[​](#sample-contract "Direct link to Sample contract")

This example smart contract queries the latest feed values for FLR/USD, BTC/USD, and ETH/USD from FTSOv2 on Flare Testnet Coston2.

FtsoV2FeedConsumer.sol

```
// SPDX-License-Identifier: MITpragma solidity >=0.8.0 <0.9.0;import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";import {IFeeCalculator} from "@flarenetwork/flare-periphery-contracts/coston2/IFeeCalculator.sol";contract FtsoV2Consumer {    bytes21 public constant flrUsdId =        0x01464c522f55534400000000000000000000000000; // "FLR/USD"    // Feed IDs, see https://dev.flare.network/ftso/feeds for full list    bytes21[] public feedIds = [        bytes21(0x01464c522f55534400000000000000000000000000), // FLR/USD        bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD        bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD    ];    function getFlrUsdPrice() external view returns (uint256, int8, uint64) {        /* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */        TestFtsoV2Interface ftsoV2 = ContractRegistry.getTestFtsoV2();        /* Your custom feed consumption logic. In this example the values are just returned. */        return ftsoV2.getFeedById(flrUsdId);    }    function getFlrUsdPriceWei() external view returns (uint256, uint64) {        /* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */        TestFtsoV2Interface ftsoV2 = ContractRegistry.getTestFtsoV2();        /* Your custom feed consumption logic. In this example the values are just returned. */        return ftsoV2.getFeedByIdInWei(flrUsdId);    }    function getFtsoV2CurrentFeedValues()        external        view        returns (            uint256[] memory _feedValues,            int8[] memory _decimals,            uint64 _timestamp        )    {        /* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */        TestFtsoV2Interface ftsoV2 = ContractRegistry.getTestFtsoV2();        /* Your custom feed consumption logic. In this example the values are just returned. */        return ftsoV2.getFeedsById(feedIds);    }}
```

[Open in Remix](https://remix.ethereum.org/#url=https://github.com/flare-foundation/developer-hub/blob/main/examples/developer-hub-solidity/FtsoV2FeedConsumer.sol&version=builtin&evmVersion=cancun&optimize=true&runs=200)

  

Don't use test interfaces in production

The `TestFtsoV2Interface` is for **testing only**, with all methods as `view` to allow rapid development without gas costs or state changes. For production, use [`FtsoV2Interface`](/ftso/solidity-reference/FtsoV2Interface), which includes `payable` methods required for real transactions and state modifications.

Make the following changes to `FtsoV2FeedConsumer.sol`:

```
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol"import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol";contract FtsoV2FeedConsumer {   //...   function getFtsoV2CurrentFeedValues()      external      returns (         uint256[] memory _feedValues,         int8[] memory _decimals,         uint64 _timestamp      )   {      ftsoV2 = ContractRegistry.getFtsoV2();      /* Your custom feed consumption logic. In this example the values are just returned. */      return ftsoV2.getFeedsById(feedIds);   }}
```

<details>
<summary>Breaking down the contract.</summary>

Breaking down the contract.

-   **Purpose**: Interacts with the Flare Network to fetch current feed values for specific cryptocurrency pairs (FLR/USD, BTC/USD, ETH/USD).
    
-   **Dependencies**:
    
-   `ContractRegistry.sol`: Used to get the addresses of various contracts on the Flare network.
    
-   `TestFtsoV2Interface.sol`: This interface allows interaction with the FTSOv2 contract, which provides real-time price feeds for various assets.
    
-   **State Variables**:
    
    -   `ftsoV2`: This is a state variable of type `TestFtsoV2Interface`. It will hold the address of the FTSO V2 contract once initialized.
    -   `feedIndexes`: An array of indexes corresponding to different price feeds. In this example:
        -   Index 0 corresponds to FLR/USD
        -   Index 2 corresponds to BTC/USD
        -   Index 9 corresponds to ETH/USD
-   **Constructor**:
    
-   The constructor is a special function that runs only once when the contract is deployed.
    

It initializes the `ftsoV2` state variable by fetching the FTSO V2 contract address using the `ContractRegistry`.

-   **Function `getFtsoV2CurrentFeedValues`**:
    
-   It is marked as `external`, meaning it can be called from outside the contract.
    
-   It is also marked as `payable`, allowing it to receive Ether when called, though in this example, the Ether is not used.
    
-   It returns three values:
    
-   `_feedValues`: The latest price values for the specified feeds.
    
-   `_decimals`: The decimal precision of each feed value.
    
-   `_timestamp`: The timestamp when the prices were fetched.
    

Inside the function:

-   The `ftsoV2.getFeedsByIndex(feedIndexes)` call retrieves the latest prices for the indexes specified in `feedIndexes`.
-   These values are then returned to the caller.

</details>

## Compile and deploy the contract[​](#compile-and-deploy-the-contract "Direct link to Compile and deploy the contract")

Configure and fund your wallet

If you have not already configured your MetaMask wallet to support Flare Testnet Coston2 and funded it with testnet C2FLR, learn how to [deploy your first smart contract](/network/getting-started). You can get testnet C2FLR from the [Coston2 Faucet](https://faucet.flare.network/coston2).

1.  [Open contract in Remix](https://remix.ethereum.org/#url=https://github.com/flare-foundation/developer-hub/blob/main/examples/developer-hub-solidity/FtsoV2FeedConsumer.sol&version=builtin&evmVersion=cancun&optimize=true&runs=200)
    
2.  Click on `FtsoV2FeedConsumer.sol` in the file explorer to open the contract in the editor.
    
3.  On the left side of Remix, click the **Solidity Compiler** tab to view the compiler settings.
    
    ![](/assets/images/0-open-solidity-compiler-tab-2899c443057e6060fda69125c510b8ec.png)
4.  Expand the **Advanced Configurations** section and make sure the **EVM Version** is set to `cancun`.
    
    ![](/assets/images/set-evm-version-remix-69f5d8d1405ae172504ea23012d0bf09.png)
5.  Click the **Compile FtsoV2FeedConsumer.sol** button to compile the contract.
    
    ![](/assets/images/2-compile-contract-a2d3909605bf679615f23e810e572d42.png)
6.  On the left side of Remix, click the **Deploy & Run transactions** tab to view the deployment settings.
    
    ![](/assets/images/3-open-deploy-72b6fdaeb1c1747d907352da5ddd89b4.png)
7.  Select the **Injected Provider - MetaMask** environment.
    
    ![](/assets/images/1-set-injected-provider-bfef3dea67a044c8ec18ecd24c8613f6.png)
8.  Click **Deploy** to deploy the contract to Flare Testnet Coston2. MetaMask opens and asks you to confirm payment for deploying the contract. Make sure MetaMask is set to Flare Testnet Coston2 before you confirm the transaction.
    
    ![](/assets/images/4-deploy-contract-788f6d97e9931f2e8b3f21bf3545e40a.png)
9.  In the MetaMask prompt, click **Confirm** to approve the transaction and spend your testnet C2FLR required to deploy the contract.
    
    ![](/assets/images/5-confirm-deploy-in-metamask-eea0d99772dce839b5c86729681c5639.png)
10.  After a few seconds, the transaction completes and your contract appears under the **Deployed/Unpinned Contracts** list in Remix. Click the contract dropdown to view its variables and functions. Click on **getFtsoV2CurrentFeedValues** to show the latest feed values and decimals.
     
     ![](/assets/images/6-query-latest-feeds-18db63ca6609ef0f31b62aacc2528ae3.png)

#### Function Returns[​](#function-returns "Direct link to Function Returns")

-   `_feedValues`: Current integer values of FLR/USD, BTC/USD, and ETH/USD. The returns are in the same order as the input `feedIndexes` array.
-   `_decimals`: Decimal places for FLR/USD, BTC/USD, and ETH/USD.
-   `_timestamp`: Timestamp of the last feed update.

The floating point value of a feed can be calculated by dividing the `feedValue` by 10^`decimals`. For example, if the feed value of BTC/USD is `6900420` and the decimal is `2`, the floating point feed value is `69004.20`.

What's next?

[Build your first FTSOv2 app](/ftso/guides/build-first-app) using Foundry, or [read feeds offchain](/ftso/guides/read-feeds-offchain) in languages like JavaScript, Python, Rust, and Go.

## Watch the video[​](#watch-the-video "Direct link to Watch the video")
