Bracle Network
  • Getting Started
    • Overview
  • Price Feeds
    • Introduction
    • How it work?
    • How to use?
      • Use Data Feed On-chain
      • Use Data Feed Off-chain
      • Become a data provider
    • Pull Model
  • Active Validation Service
    • Active Validation Service
  • Data Availability Service
    • Data Availability Service
  • BTC LSD Restaking
    • BTC LSD Restaking
  • Key Addresses
    • Price Feed Contract Addresses
Powered by GitBook
On this page
  1. Price Feeds
  2. How to use?

Use Data Feed Off-chain

Javascript

This example uses ethers.js to retrieve feed data from the ETH / USD feed on the ArbitrumSepolia testnet.

/**
 * THIS IS EXAMPLE CODE THAT USES HARDCODED VALUES FOR CLARITY.
 * THIS IS EXAMPLE CODE THAT USES UN-AUDITED CODE.
 * DO NOT USE THIS CODE IN PRODUCTION.
 */

const { ethers } = require("ethers") // for nodejs only
const provider = new ethers.providers.JsonRpcProvider("https://endpoints.omniatech.io/v1/arbitrum/sepolia/public")
const aggregatorABI = [
  {
    inputs: [],
    name: "decimals",
    outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
    stateMutability: "view",
    type: "function",
  },
  {
    inputs: [],
    name: "description",
    outputs: [{ internalType: "string", name: "", type: "string" }],
    stateMutability: "view",
    type: "function",
  },
  {
    inputs: [{ internalType: "uint80", name: "_roundId", type: "uint80" }],
    name: "getRoundData",
    outputs: [
      { internalType: "uint80", name: "roundId", type: "uint80" },
      { internalType: "int256", name: "answer", type: "int256" },
      { internalType: "uint256", name: "startedAt", type: "uint256" },
      { internalType: "uint256", name: "updatedAt", type: "uint256" },
      { internalType: "uint80", name: "answeredInRound", type: "uint80" },
    ],
    stateMutability: "view",
    type: "function",
  },
  {
    inputs: [],
    name: "latestRoundData",
    outputs: [
      { internalType: "uint80", name: "roundId", type: "uint80" },
      { internalType: "int256", name: "answer", type: "int256" },
      { internalType: "uint256", name: "startedAt", type: "uint256" },
      { internalType: "uint256", name: "updatedAt", type: "uint256" },
      { internalType: "uint80", name: "answeredInRound", type: "uint80" },
    ],
    stateMutability: "view",
    type: "function",
  },
  {
    inputs: [],
    name: "version",
    outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
    stateMutability: "view",
    type: "function",
  },
]
const addr = "0xbF13EE58Bf62500FE87e7389faB633ff95dec029"
const priceFeed = new ethers.Contract(addr, aggregatorABI, provider)
priceFeed.latestRoundData().then((roundData) => {
  // Do something with roundData
  console.log("Latest Round Data", roundData)
})
PreviousUse Data Feed On-chainNextBecome a data provider

Last updated 1 year ago