I have a working contract deployed on rinkeby, I'm trying to add there a function to get the current ETH/USD price using ChainLink's AggregatorV3Interface .
When testing the needed function in Remix, (environment=Injected Provider - Metamask(Rinkeby)) everything works fine:
pragma solidity 0.8.7; import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; contract Testing { function getPrice() public view returns (uint256) { AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e); (, int256 answer, , , ) = priceFeed.latestRoundData(); // ETH/USD rate in 18 digit return uint256(answer * 10000000000);}} However when I take the same function and put in my contract, deploy the whole thing on Rinkeby, then on my front-end i call it and get this error:
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"code":-32000,"message":"execution reverted"}, method="call", transaction={"from":"0x34aaAa5Ccfa7A0899C1FeC04C43BF0D87Ea0F3fB","to":"0xee42aa31f9E9f0AA063DE5a6A773c6e345bef783","data":"0x98d5fdca","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.0)
- Why would a
public viewfunction need any gas to execute itself? - What do I change in the function to make it work inside of my contract?