0

I deployed a smart contract to Ganache as below code:

// SPDX-License-Identifier: MIT
// Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0
pragma solidity ^0.8.13;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "./ConvertLib.sol";

// This is just a simple example of a coin-like contract.
// It is not ERC20 compatible and cannot be expected to talk to other
// coin/token contracts.

contract MetaCoin {
        AggregatorV3Interface internal priceFeed;

    constructor() {
        
                priceFeed = AggregatorV3Interface(0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e);
    }

        function getLatestPrice() public view returns (int) {
        (
            /*uint80 roundID*/,
            int price,
            /*uint startedAt*/,
            /*uint timeStamp*/,
            /*uint80 answeredInRound*/
        ) = priceFeed.latestRoundData();
        return price;
    }
}

when I call the method getLatestPrice from web3 in chrome,

coinContract.methods.getLatestPrice().send({ from: xxxx });

the MetaMask wallet popup but shows an error We were not able to estimate gas. There might be an error in the contract and this transaction may fail.

enter image description here

but if I change the code to use call instead of send,

coinContract.methods.getLatestPrice().call();

I got this error:

{
  "message": "VM Exception while processing transaction: revert",
  "code": -32000,
  "data": {
    "0xc431aacd735f5e37f257d9ce3ad00d0ce66c41447ac8d8b16760a6dbc76eb8e2": {
      "error": "revert",
      "program_counter": 1020,
      "return": "0x"
    },
    "stack": "RuntimeError: VM Exception while processing transaction: revert\n    at Function.RuntimeError.fromResults (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/utils/runtimeerror.js:94:13)\n    at /Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/blockchain_double.js:568:26",
    "name": "RuntimeError"
  }
}

I don't know what wrong with my code

1
  • Is there actually a v3 Aggregator deployed at 0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e on your local fork?
    – Alkhara
    Commented Nov 3, 2022 at 6:07

1 Answer 1

0

You want to check if the contract address and ABI you are deploying to Ganache is correct. If it is, check if the method you're calling is correct. Finally, check if the parameters in the function call are correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.