I'm new to blockchain development, I have done some simple projects before and I had no issue in calling the functions with web3js, but now I'm trying to run a call function on a smart contract using web3js and for some reason I get this error Returned values aren't valid, did it run Out of Gas?, I don't know what is the issue here, also all of my other tests are run successfuly, I can create a new Lottery smart contract using the LotteryFactory contract with no issue, my only problem is running the getDeployedLotteries function. Here is the solidity code:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

 * @title Storage
 * @dev Store & retrieve value in a variable

contract LotteryFactory {
    Lottery[] public deployedLotteries;

    function createLottery(uint256 minimum) public {
        Lottery newLottery = new Lottery(minimum, msg.sender);

    function getDeployedLotteries() public view returns (Lottery[] memory) {
        return deployedLotteries;

contract Lottery {...}

This is my test file:

const ganache = require('ganache-cli')
const assert = require('assert')
const Web3 = require('web3')
const fs = require('fs')

const web3 = new Web3(ganache.provider())

const { abi, bytecode } = JSON.parse(

const address = '0x6fe3d597e18DC780e7FcAFe821F963946F55EcE6'

let lotteryFactory
let accounts

beforeEach(async () => {
  accounts = await web3.eth.getAccounts()
  lotteryFactory = await new web3.eth.Contract(abi, address)

it('gets back all deployed loteries', async () => {
    try {
      const lotteries = await lotteryFactory.methods
    } catch (error) {
  • Are you connecting to the network where the address 0x6fe3d597e18DC780e7FcAFe821F963946F55EcE6 was deployed? Can you call other methods? Which network did you deploy to? ropsten, rinkeby, ganache,..
    – Ismael
    Commented Sep 17, 2021 at 2:58
  • @Ismael, I'm on a local ganache network. all the other methods are working just fine. exept for the ones that need to be called with the .call() function. Anything with .send() works just fine
    – Dastan
    Commented Sep 17, 2021 at 9:57
  • I said in another thread that if you deployed to rinkeby then you can't access it while connected to ganache.
    – Ismael
    Commented Sep 18, 2021 at 14:57
  • in Rinkeby everything works just fine, but when I deploy to ganache and try to run a .call() function. It just gives me that error. Don't know what's the reason.
    – Dastan
    Commented Sep 19, 2021 at 15:08
  • Usually it is the other way around. Are you using a recent ganache version? Do you have a repo to try? Can you try in a different computer/VM?
    – Ismael
    Commented Sep 19, 2021 at 17:45

1 Answer 1


Try calling the createLottery function once in your tests. Without doing that, the return value for getDeployedLottery() would be an empty array, which is a falsy value, so assert.ok would fail.

  • I actually have done that, before running the getDeployedLotteries() test. I ran createLottery(), which was successful. all the other tests are a success accpet for the ones that are using the .call() function. anything with .send() works just fine
    – Dastan
    Commented Sep 17, 2021 at 9:55

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.