I have written the following code:
const web3 = new Web3(
'https://polygon-mainnet.infura.io/v3/<INFURA_PROJECT_ID>'
)
const aggregatorV3InterfaceABI = [{ "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 = '0xAB594600376Ec9fD91F8e885dADF0CE036862dE0'
const priceFeed = web3.eth.contract(aggregatorV3InterfaceABI, addr)
priceFeed.methods
.latestRoundData()
.call()
.then((roundData) => {
console.log(roundData.answer);
})
I'm using the Infura API to talk to smart contracts on the Polygon mainnet.
However, I'm getting the following error on console:
Uncaught TypeError: Cannot read properties of undefined (reading 'latestRoundData')
My libraries and their versions are as follows:
> web3.js : 0.19.0
> Truffle : v5.4.32
> truffle-contract.min.js : 4.0.31