Skip to content

Use Chainlink Data Feed in Js file without hard coding Data feed Contract's ABI #2361

Discussion options

You must be logged in to vote

I got one working code as shown below:

const 
  aggregatorV3InterfaceABI
= require("@chainlink/contracts/abi/v0.8/AggregatorV3Interface.json");
const { ethers } = require("ethers") //ethers.js

async function main() {
    const provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/eth_goerli")
    const addr = "0xA39434A63A52E749F02807ae27335515BA4b07F7"
    const priceFeed = new ethers.Contract(addr, aggregatorV3InterfaceABI, provider)
    let {answer} = await priceFeed.latestRoundData()
    console.log(answer.toString())
}
main()
  .then(() => {
    process.exit(0);
  })
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

OUTPUT:

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@GarvitKarnwal
Comment options

Comment options

You must be logged in to vote
1 reply
@GarvitKarnwal
Comment options

Comment options

You must be logged in to vote
3 replies
@alymurtazamemon
Comment options

@GarvitKarnwal
Comment options

@alymurtazamemon
Comment options

Answer selected by GarvitKarnwal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants