# FtsoV2Interface

> Primary interface for interacting with FTSOv2.

> 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/solidity-reference/FtsoV2Interface

Primary interface for interacting with FTSOv2. This is a long-term support (LTS) interface, designed to ensure continuity even as underlying contracts evolve or protocols migrate to new versions.

Sourced from `FtsoV2Interface.sol` on [GitHub](https://github.com/flare-foundation/flare-smart-contracts-v2/blob/main/contracts/userInterfaces/LTS/FtsoV2Interface.sol).

## Functions[​](#functions "Direct link to Functions")

### getFeedById[​](#getfeedbyid "Direct link to getFeedById")

Returns stored data of a feed. A fee (calculated by the FeeCalculator contract) may need to be paid.

```
function getFeedById(    bytes21 _feedId) external payable returns (    uint256 _value,    int8 _decimals,    uint64 _timestamp);
```

#### Parameters[​](#parameters "Direct link to Parameters")

-   `_feedId`: The id of the feed.

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

-   `_value`: The value for the requested feed.
-   `_decimals`: The decimal places for the requested feed.
-   `_timestamp`: The timestamp of the last update.

<details>
<summary>Sample contract usage</summary>

Sample contract usage

FTSOV2FeedById.sol

```
// SPDX-License-Identifier: MITpragma solidity >=0.8.0 <0.9.0;import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";/* THIS IS A TEST IMPORT, in production use: import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol"; */import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";/** * THIS IS AN EXAMPLE CONTRACT. * DO NOT USE THIS CODE IN PRODUCTION. */contract FtsoV2FeedConsumerById {    TestFtsoV2Interface internal ftsoV2;    // Example Feed ID for FLR/USD    bytes21 public feedId =        bytes21(0x01464c522f55534400000000000000000000000000); // FLR/USD    /**     * Get the current value of a specific feed by its ID.     * @return _feedValue The latest price value of the feed.     * @return _decimals The decimal precision of the feed value.     * @return _timestamp The timestamp of the last feed update.     */    function getFtsoV2FeedValueById()        external        payable        returns (uint256 _feedValue, int8 _decimals, uint64 _timestamp)    {        /* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */        ftsoV2 = ContractRegistry.getTestFtsoV2();        /* Retrieves the latest value, decimals, and timestamp for the specified feed ID. */        return ftsoV2.getFeedById(feedId);    }}
```

</details>

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

### getFeedByIdInWei[​](#getfeedbyidinwei "Direct link to getFeedByIdInWei")

Returns value in wei and timestamp of a feed. A fee (calculated by the FeeCalculator contract) may need to be paid.

```
function getFeedByIdInWei(    bytes21 _feedId) external payable returns (    uint256 _value,    uint64 _timestamp);
```

#### Parameters[​](#parameters-1 "Direct link to Parameters")

-   `_feedId`: The id of the feed.

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

-   `_value`: The value for the requested feed in wei (i.e. with 18 decimal places).
-   `_timestamp`: The timestamp of the last update.

<details>
<summary>Sample contract usage</summary>

Sample contract usage

FTSOV2FeedByIdWei.sol

```
// SPDX-License-Identifier: MITpragma solidity >=0.8.0 <0.9.0;import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";/* THIS IS A TEST IMPORT, in production use: import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol"; */import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";/** * THIS IS AN EXAMPLE CONTRACT. * DO NOT USE THIS CODE IN PRODUCTION. */contract FtsoV2FeedTracker {    TestFtsoV2Interface internal ftsoV2;    bytes21 public feedId =        bytes21(0x01464c522f55534400000000000000000000000000); // FLR/USD    // Event to track feed retrieval    event FeedFetched(bytes21 feedId, uint256 valueInWei, uint64 timestamp);    /**     * Get the current value of a specific feed by its index, in wei.     * @return _feedValue The latest price value of the feed in wei.     * @return _timestamp The timestamp of the last update for the feed.     */    function getFeedValueByIdWei()        external        payable        returns (uint256 _feedValue, uint64 _timestamp)    {        /* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */        ftsoV2 = ContractRegistry.getTestFtsoV2();        // Retrieve feed value and timestamp from the FtsoV2 contract        (_feedValue, _timestamp) = ftsoV2.getFeedByIdInWei(feedId);        // Emit an event to log the feed retrieval        emit FeedFetched(feedId, _feedValue, _timestamp);    }}
```

</details>

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

### getFeedsById[​](#getfeedsbyid "Direct link to getFeedsById")

Returns stored data of each feed. A fee (calculated by the FeeCalculator contract) may need to be paid.

```
function getFeedsById(    bytes21[] _feedIds) external payable returns (    uint256[] _values,    int8[] _decimals,    uint64 _timestamp);
```

#### Parameters[​](#parameters-2 "Direct link to Parameters")

-   `_feedIds`: The list of feed ids.

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

-   `_values`: The list of values for the requested feeds.
-   `_decimals`: The list of decimal places for the requested feeds.
-   `_timestamp`: The timestamp of the last update.

<details>
<summary>Sample contract usage</summary>

Sample contract usage

FTSOV2FeedsById.sol

```
// SPDX-License-Identifier: MITpragma solidity >=0.8.0 <0.9.0;import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";/* THIS IS A TEST IMPORT, in production use: import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol"; */import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";/** * THIS IS AN EXAMPLE CONTRACT. * DO NOT USE THIS CODE IN PRODUCTION. */contract FtsoV2FeedConsumer {    TestFtsoV2Interface internal ftsoV2;    // 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    ];    /**     * Get the current value of the feeds.     */    function getFtsoV2CurrentFeedValues()        external        returns (            uint256[] memory _feedValues,            int8[] memory _decimals,            uint64 _timestamp        )    {        /* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */        ftsoV2 = ContractRegistry.getTestFtsoV2();        /* Your custom feed consumption logic. In this example the values are just returned. */        return ftsoV2.getFeedsById(feedIds);    }}
```

</details>

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

### getFeedsByIdInWei[​](#getfeedsbyidinwei "Direct link to getFeedsByIdInWei")

Returns value of each feed and a timestamp. For some feeds, a fee (calculated by the FeeCalculator contract) may need to be paid.

```
function getFeedsByIdInWei(    bytes21[] _feedIds) external payable returns (    uint256[] _values,    uint64 _timestamp);
```

#### Parameters[​](#parameters-3 "Direct link to Parameters")

-   `_feedIds`: Ids of the feeds.

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

-   `_values`: The list of values for the requested feeds in wei (i.e. with 18 decimal places).
-   `_timestamp`: The timestamp of the last update.

<details>
<summary>Sample contract usage</summary>

Sample contract usage

FTSOV2FeedsByIdWei.sol

```
// SPDX-License-Identifier: MITpragma solidity >=0.8.0 <0.9.0;import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";/* THIS IS A TEST IMPORT, in production use: import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol"; */import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";/** * THIS IS AN EXAMPLE CONTRACT. * DO NOT USE THIS CODE IN PRODUCTION. */contract FtsoV2FeedConsumer {    // 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    ];    // Event to log feed values retrieval    event FeedValuesRetrieved(        bytes21[] indexed feedIds,        uint256[] values,        uint64 timestamp    );    /**     * Get the current value of the feeds in wei.     * A fee may be required for certain feeds, calculated by the FeeCalculator contract.     * @param _feedIds The IDs of the feeds to retrieve values for.     * @return _values The list of values for the requested feeds in wei.     * @return _timestamp The timestamp of the last update.     */    function getFeedsByIdInWei(        bytes21[] calldata _feedIds    ) external view returns (uint256[] memory _values, uint64 _timestamp) {        // Ensure that the length of the feed IDs is non-zero        require(_feedIds.length > 0, "No feed IDs provided");        /* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */        TestFtsoV2Interface ftsoV2 = ContractRegistry.getTestFtsoV2();        // Retrieve the feed values and timestamp from the FTSOv2 contract        return ftsoV2.getFeedsByIdInWei(_feedIds);    }}
```

</details>

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

### getFtsoProtocolId[​](#getftsoprotocolid "Direct link to getFtsoProtocolId")

Returns the FTSO protocol id.

```
function getFtsoProtocolId() external view returns (uint256);
```

### getSupportedFeedIds[​](#getsupportedfeedids "Direct link to getSupportedFeedIds")

Returns the list of currently supported (active) feed ids. To enumerate every feed id that has ever existed, combine the result with [`getFeedIdChanges`](#getfeedidchanges).

```
function getSupportedFeedIds()    external view    returns (bytes21[] memory _feedIds);
```

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

-   `_feedIds`: The list of supported feed ids.

### getFeedIdChanges[​](#getfeedidchanges "Direct link to getFeedIdChanges")

Returns the list of feed id changes (old/new pairs).

```
function getFeedIdChanges()    external view    returns (FeedIdChange[] memory _feedIdChanges);
```

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

-   `_feedIdChanges`: The list of changed feed id pairs.

### calculateFeeById[​](#calculatefeebyid "Direct link to calculateFeeById")

Calculates the fee for fetching a single feed.

```
function calculateFeeById(bytes21 _feedId)    external view    returns (uint256 _fee);
```

#### Parameters[​](#parameters-4 "Direct link to Parameters")

-   `_feedId`: The id of the feed.

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

-   `_fee`: The fee for fetching the feed.

### calculateFeeByIds[​](#calculatefeebyids "Direct link to calculateFeeByIds")

Calculates the fee for fetching multiple feeds at once.

```
function calculateFeeByIds(bytes21[] memory _feedIds)    external view    returns (uint256 _fee);
```

#### Parameters[​](#parameters-5 "Direct link to Parameters")

-   `_feedIds`: The list of feed ids.

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

-   `_fee`: The combined fee.

### verifyFeedData[​](#verifyfeeddata "Direct link to verifyFeedData")

Checks if the feed data is valid (i.e. is part of the confirmed Merkle tree).

```
function verifyFeedData(    struct FtsoV2Interface.FeedDataWithProof _feedData) external view returns (    bool);
```

#### Parameters[​](#parameters-6 "Direct link to Parameters")

-   `_feedData`: Structure containing data about the feed (FeedData structure) and Merkle proof.

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

-   `_0`: true if the feed data is valid.

<details>
<summary>Sample contract usage</summary>

Sample contract usage

FTSOV2AnchorConsumer.sol

```
// SPDX-License-Identifier: MITpragma solidity >=0.8.0 <0.9.0;import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol";import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";/** * THIS IS AN EXAMPLE CONTRACT. * DO NOT USE THIS CODE IN PRODUCTION. */contract FtsoV2AnchorFeedConsumer {    bytes21 private constant FLR_USD_ID =        0x01464c522f55534400000000000000000000000000;    bytes21 private constant BTC_USD_ID =        0x014254432f55534400000000000000000000000000;    bytes21 private constant ETH_USD_ID =        0x014554482f55534400000000000000000000000000;    mapping(uint32 => mapping(bytes21 => TestFtsoV2Interface.FeedData))        public provenFeeds;    // Track which feeds have been proven per round for easy enumeration    mapping(uint32 => bytes21[]) private _provenFeedIdsByRound;    mapping(uint32 => mapping(bytes21 => bool)) private _isProven;    event FeedProven(        uint32 indexed votingRoundId,        bytes21 indexed id,        int32 value,        uint16 turnoutBIPS,        int8 decimals    );    function savePrice(        TestFtsoV2Interface.FeedDataWithProof calldata data    ) external {        /* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */        TestFtsoV2Interface ftsoV2 = ContractRegistry.getTestFtsoV2();        // Step 1: Verify the proof        require(ftsoV2.verifyFeedData(data), "Invalid proof");        // Step 2: Ensure the proof is for the desired feedId to avoid manipulation        require(            data.body.id == FLR_USD_ID ||                data.body.id == BTC_USD_ID ||                data.body.id == ETH_USD_ID,            "Proof is not for desired feedId"        );        // Step 3: Use the feed data with app specific logic        // Here the feed data is saved        uint32 roundId = data.body.votingRoundId;        bytes21 id = data.body.id;        provenFeeds[roundId][id] = data.body;        // Record id for enumeration if first time proven in this round        if (!_isProven[roundId][id]) {            _isProven[roundId][id] = true;            _provenFeedIdsByRound[roundId].push(id);        }        emit FeedProven(            roundId,            id,            data.body.value,            data.body.turnoutBIPS,            data.body.decimals        );    }    // Returns whether a given feed id has been proven for the round    function isProven(        uint32 votingRoundId,        bytes21 id    ) external view returns (bool) {        return _isProven[votingRoundId][id];    }    // Returns all feed ids proven for a voting round    function getProvenFeedIds(        uint32 votingRoundId    ) external view returns (bytes21[] memory) {        return _provenFeedIdsByRound[votingRoundId];    }    // Returns all proven feeds (full FeedData) for a voting round    function getProvenFeeds(        uint32 votingRoundId    ) external view returns (TestFtsoV2Interface.FeedData[] memory) {        bytes21[] memory ids = _provenFeedIdsByRound[votingRoundId];        TestFtsoV2Interface.FeedData[]            memory out = new TestFtsoV2Interface.FeedData[](ids.length);        for (uint256 i = 0; i < ids.length; i++) {            out[i] = provenFeeds[votingRoundId][ids[i]];        }        return out;    }}
```

</details>

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

## Structures[​](#structures "Direct link to Structures")

### FeedData[​](#feeddata "Direct link to FeedData")

Feed data structure

```
struct FeedData {  uint32 votingRoundId;  bytes21 id;  int32 value;  uint16 turnoutBIPS;  int8 decimals;}
```

### FeedDataWithProof[​](#feeddatawithproof "Direct link to FeedDataWithProof")

Feed data with proof structure

```
struct FeedDataWithProof {    bytes32[] proof;    struct FtsoV2Interface.FeedData body;}
```

### FeedIdChange[​](#feedidchange "Direct link to FeedIdChange")

Pair representing a feed id rename (e.g. when a feed is relabelled).

```
struct FeedIdChange {    bytes21 oldFeedId;    bytes21 newFeedId;}
```

## Events[​](#events "Direct link to Events")

### FeedIdChanged[​](#feedidchanged "Direct link to FeedIdChanged")

Emitted when a feed id is changed (e.g. when a feed is renamed).

```
event FeedIdChanged(bytes21 indexed oldFeedId, bytes21 indexed newFeedId);
```
