Agent documentation index: llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Skip to main content

Read feeds offchain

This guide provides code examples demonstrating how to read FTSOv2 feeds offchain using various programming languages. To read a block-latency feed offchain, you need three key pieces of information:

  1. RPC Endpoint URL: The RPC Endpoint URL determines which network your code will interact with. You can use a node provider service or point to your own RPC node. A comprehensive list of public and private RPC endpoints for all Flare networks is available on the Network Configuration page.

  2. Contract Address: Feeds are served on the FtsoV2 contract, whose address varies by network. You can obtain this address in two ways:

    • From the Solidity Reference page: Find the FtsoV2 address for each network on the Solidity Reference page.

      OR

    • Query the FlareContractRegistry Contract: The FlareContractRegistry contract has the same address across all networks. You can query it to get the FtsoV2 contract address. Refer to the specific language guides for examples: - JavaScript - Python - Rust - Go

  3. Feed IDs: The feeds you want to read are uniquely identified by their ID. A list of feed IDs is provided on the Block-Latency Feeds page.

tip

All examples in this guide are available at developer-hub/examples.

This example uses web3.js and Flare Periphery Contract Artifacts to retrieve FTSOv2 feed data for FLR/USD, BTC/USD, and ETH/USD on Flare Testnet Coston2.

npm install web3
npm install @flarenetwork/flare-periphery-contract-artifacts
ftsov2_consumer.js
// THIS IS EXAMPLE CODE. DO NOT USE THIS CODE IN PRODUCTION.
import { Web3 } from "web3";

import { interfaceToAbi } from "@flarenetwork/flare-periphery-contract-artifacts";

// FtsoV2 address (Flare Testnet Coston2)
// See https://dev.flare.network/ftso/solidity-reference
const FTSOV2_ADDRESS = "0x3d893C53D9e8056135C26C8c638B76C8b60Df726";
const RPC_URL = "https://coston2-api.flare.network/ext/C/rpc";
const FEED_IDS = [
"0x01464c522f55534400000000000000000000000000", // FLR/USD
"0x014254432f55534400000000000000000000000000", // BTC/USD
"0x014554482f55534400000000000000000000000000", // ETH/USD
];
// ABI for FtsoV2
const abi = interfaceToAbi("FtsoV2Interface", "coston2");

export async function main() {
// Connect to an RPC node
const w3 = new Web3(RPC_URL);
// Set up contract instance
const ftsov2 = new w3.eth.Contract(abi, FTSOV2_ADDRESS);
// Fetch current feeds
const res = await ftsov2.methods.getFeedsById(FEED_IDS).call();
// Log results
console.log("Feeds:", res["0"]);
console.log("Decimals:", res["1"]);
console.log("Timestamp:", res["2"]);
return res;
}

main();