1

I have a test function:

function test(uint[400] subscriptions, uint[400] subscriptionIndexes) public view returns 
      (uint[4000], uint[4000], uint[400]) {

        uint[4000] memory postSenders;
        uint[4000] memory postIds;

        for (uint i = 0; i < 4000; i++) {

            postSenders[i] = 1;
            postIds[i] = 1;
        }

        return (postSenders, postIds, subscriptionIndexes);
    }

If I connect Remix to Ganache, and call the function by copy pasting the parameters into the Remix IDE blue function box then it runs fine. If I try to call the same contract on the same Ganache network using web3 v 1.0 I get an out of gas error.

 let subs = [1,1, ... ,1]
  let indexes = [1,1, ... ,1]
  let results = await contract.methods.test(subs, indexes).call()

If I reduce the number of loops in the test function eventually it will stop giving the out of gas error. Does anyone know what might be causing the problem?

The function also runs fine on Rinkeby via Remix.

Thanks!

2

Remix is particular because it calculates how much gas is required by the call.

Web3 is expecting you to supply enough gas. Its default value used to be lower than 100k gas.

You can set the value for call and send, for example to send 1M gas

let subs = [1,1, ... ,1]
let indexes = [1,1, ... ,1]
let results = await contract.methods.test(subs, indexes).call({
  gas: 1000000
})

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.