0

I need to call a getter function from my contract, but I'm getting the following error:

Error Error: Internal JSON-RPC error.
{
  "message": "VM Exception while processing transaction: revert",
  "code": -32000,
  "data": {
    "0xc3a8b1710c15f6ba59f9fefea5d9da656aabb8495834fb56c9b4277df741d610": {
      "error": "revert",
      "program_counter": 305,
      "return": "0x"
    },
    "stack": "RuntimeError: VM Exception while processing transaction: revert\n    at Function.RuntimeError.fromResults (/tmp/.mount_ganach04KHEZ/resources/static/node/node_modules/ganache-core/lib/utils/runtimeerror.js:94:13)\n    at /tmp/.mount_ganach04KHEZ/resources/static/node/node_modules/ganache-core/lib/blockchain_double.js:568:26",
    "name": "RuntimeError"
  }
}
    at Object._fireError (index.js:50)
    at sendTxCallback (index.js:540)
    at cb (util.js:689)
    at callbackifyOnRejected (util.js:666)
    at Item.push../node_modules/process/browser.js.Item.run (browser.js:153)
    at drainQueue (browser.js:123)

My contract version is ^0.8.0 and the code related to the function is:

ItemForSale[] public itemsForSale;
function totalItemsForSale() external view returns(uint256) {
    return itemsForSale.length;
  }

My attempt to call the function from the front-end using web3 is:

const totalItemsForSale = await marketplaceContract.methods.totalItemsForSale().call();
4
  • DId you try any other methods? Jul 16 at 17:30
  • Are you using the correct artifacts for the contract? Do you use truffle or hardhat? What network are you using? How is the struct ItemForSale declared? Could you, please, provide more Solidity code? Jul 16 at 17:59
  • 1
    I just found the problem. I was passing the address from the other contract to the MarketplaceContract. Jul 16 at 19:16
  • 1
    @NatalieBravo Can you add that as answer so the question can be marked as resolved?
    – Ismael
    Jul 18 at 18:15
0

I just found the problem. I was passing the address from the other contract to the MarketplaceContract. A silly mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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