Skip to content

Commit

Permalink
Add off-chain feed query guide
Browse files Browse the repository at this point in the history
  • Loading branch information
dineshpinto committed Jun 6, 2024
1 parent 90a23c5 commit 8ed161f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/2-network.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Flare has four networks, each serving different purposes, so choosing the right

- **Songbird Canary-Network.** Experimental proving ground for Flare, test your applications in a real-world environment.

- **Songbird Testnet Coston.** This is the testnet for the Songbird network.
- **Songbird Testnet Coston.** The testnet for Songbird network.

The most common development tracks are:

Expand Down
26 changes: 15 additions & 11 deletions docs/ftso/guides/read-feeds-offchain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ sidebar_position: 1
import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";

This guide contains code examples that demonstrate how to read FTSOv2 feeds off-chain using different programming languages.
This guide contains code examples that demonstrate how to read FTSOv2 feeds off-chain using different programming languages. To read a block-latency feed off-chain you need two pieces of information:

1. **RPC Endpoint URL:** This determines which network that code will interact with. You can use a node provider service or point to your own client. A list of public and private RPC endpoints for all Flare networks is provided on the [Network Configuration](../../network#configuration) page.

2. **FastUpdater Contract Address:** The address for the `FastUpdater` contract is different for each network. You can query this by calling the `FlareContractRegistry`, which has the same address across all Flare networks `0xaD67FE66660Fb8dFE9d6b1b4240d8650e30F6019`. Examples for how to query the `FlareContractRegistry` are given in the language guides using [Python](/guides/flare-for-python-developers#make-query), [Rust](/guides/flare-for-rust-developers#make-query), [JavaScript](/guides/flare-for-javascript-developers#make-query), and [Go](/guides/flare-for-go-developers#make-query).

## Python

Expand Down Expand Up @@ -37,7 +41,7 @@ import asyncio
from web3 import AsyncHTTPProvider, AsyncWeb3

# FastUpdater address (Songbird Testnet Coston)
FTSO_ADDRESS = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9"
ADDRESS = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9"
RPC_URL = "https://rpc.ankr.com/flare_coston"
# Feed indexes: 0 = FLR/USD, 2 = BTC/USD, 9 = ETH/USD
FEED_INDEXES = [0, 2, 9]
Expand All @@ -49,7 +53,7 @@ async def main() -> None:
# Connect to an RPC node
w3 = AsyncWeb3(AsyncHTTPProvider(RPC_URL))
# Set up contract instance
ftsov2 = w3.eth.contract(address=FTSO_ADDRESS, abi=ABI)
ftsov2 = w3.eth.contract(address=ADDRESS, abi=ABI)
# Fetch current feeds
feeds, decimals, timestamp = await ftsov2.functions.fetchCurrentFeeds(
FEED_INDEXES
Expand Down Expand Up @@ -90,7 +94,7 @@ This example shows two ways, one using [web3.js](https://github.com/web3/web3.js
import { Web3 } from "web3";

// FastUpdater address (Songbird Testnet Coston)
const FTSO_ADDRESS = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9";
const ADDRESS = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9";
const RPC_URL = "https://rpc.ankr.com/flare_coston";
// Feed indexes: 0 = FLR/USD, 2 = BTC/USD, 9 = ETH/USD
const FEED_INDEXES = [0, 2, 9];
Expand All @@ -102,7 +106,7 @@ This example shows two ways, one using [web3.js](https://github.com/web3/web3.js
// Connect to an RPC node
const w3 = new Web3(RPC_URL);
// Set up contract instance
const ftsov2 = new w3.eth.Contract(ABI, FTSO_ADDRESS);
const ftsov2 = new w3.eth.Contract(ABI, ADDRESS);
// Fetch current feeds
const res = await ftsov2.methods.fetchCurrentFeeds(FEED_INDEXES).call();
// Log results
Expand All @@ -122,7 +126,7 @@ This example shows two ways, one using [web3.js](https://github.com/web3/web3.js
import { ethers } from "ethers";

// FastUpdater address (Songbird Testnet Coston)
const FTSO_ADDRESS = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9";
const ADDRESS = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9";
const RPC_URL = "https://rpc.ankr.com/flare_coston";
// Feed indexes: 0 = FLR/USD, 2 = BTC/USD, 9 = ETH/USD
const FEED_INDEXES = [0, 2, 9];
Expand All @@ -134,7 +138,7 @@ This example shows two ways, one using [web3.js](https://github.com/web3/web3.js
// Connect to an RPC node
const provider = new ethers.JsonRpcProvider(RPC_URL);
// Set up contract instance
const ftsov2 = new ethers.Contract(FTSO_ADDRESS, ABI, provider);
const ftsov2 = new ethers.Contract(ADDRESS, ABI, provider);
// Fetch current feeds
const res = await ftsov2.fetchCurrentFeeds(FEED_INDEXES);
// Log results
Expand Down Expand Up @@ -174,14 +178,14 @@ sol!(
#[tokio::main]
async fn main() -> Result<()> {
// FastUpdater address (Songbird Testnet Coston)
let ftso_address = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9".parse()?;
let address = "0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9".parse()?;
let rpc_url = "https://rpc.ankr.com/flare_coston".parse()?;
// Feed indexes: 0 = FLR/USD, 2 = BTC/USD, 9 = ETH/USD
let feed_indexes = vec![U256::from(0_u32), U256::from(2_u32), U256::from(9_u32)];
// Connect to an RPC node
let provider = ProviderBuilder::new().on_http(rpc_url);
// Set up contract instance
let ftsov2 = FtsoV2::new(ftso_address, provider);
let ftsov2 = FtsoV2::new(address, provider);
// Fetch current feeds
let FtsoV2::fetchCurrentFeedsReturn {
_feeds,
Expand Down Expand Up @@ -226,12 +230,12 @@ import (

func FtsoV2Consumer() {
// FastUpdater address (Songbird Testnet Coston)
ftsoAddress := common.HexToAddress("0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9")
address := common.HexToAddress("0x9B931f5d3e24fc8C9064DB35bDc8FB4bE0E862f9")
rpcUrl := "https://rpc.ankr.com/flare_coston"
// Connect to an RPC node
client, _ := ethclient.Dial(rpcUrl)
// Set up contract instance
ftsov2, _ := NewFastUpdater(ftsoAddress, client)
ftsov2, _ := NewFastUpdater(address, client)
// Feed indexes: 0 = FLR/USD, 2 = BTC/USD, 9 = ETH/USD
feedIndexes := []*big.Int{big.NewInt(0), big.NewInt(2), big.NewInt(9)}
// Fetch current feeds
Expand Down
2 changes: 1 addition & 1 deletion guides/2024-05-24-flare-for-go-developers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ abigen --abi FlareContractRegistry.abi --pkg main --type contract --out FlareCon

### Make query

You can query the `FlareContractRegistry` contract to get the addresses of other Flare contracts.
You can now query the `FlareContractRegistry` contract to get the addresses of other Flare contracts.

For example, querying it for the address of the `WNat` contract:

Expand Down
2 changes: 1 addition & 1 deletion guides/2024-05-25-flare-for-javascript-developers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ To fetch a contract's ABI programmatically, you can query the [Flare Blockchain

### Make query

Using this `abi` you can query the `FlareContractRegistry` contract to get the addresses of other Flare contracts.
You can now query the `FlareContractRegistry` contract to get the addresses of other Flare contracts.

For example, querying it for the address of the `WNat` contract:

Expand Down
2 changes: 1 addition & 1 deletion guides/2024-05-26-flare-for-rust-developers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ To fetch a contract's ABI, you can use Flarescan. Copy the **Contract ABI** from

### Make query

You can query the `FlareContractRegistry` contract to get the addresses of other Flare contracts.
You can now query the `FlareContractRegistry` contract to get the addresses of other Flare contracts.

For example, querying it for the address of the `WNat` contract:

Expand Down
2 changes: 1 addition & 1 deletion guides/2024-05-27-flare-for-python-developers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ To fetch a contract's ABI programmatically, you can query the [Flare Blockchain

### Make query

Using this `abi` you can query the `FlareContractRegistry` contract to get the addresses of other Flare contracts.
You can now query the `FlareContractRegistry` contract to get the addresses of other Flare contracts.

For example, querying it for the address of the `WNat` contract:

Expand Down

0 comments on commit 8ed161f

Please sign in to comment.