2

I am trying to test and deploy my contract using the latest ganache-cli v6.0.3 (ganache-core: 2.0.2) with Remix (http! version) on http://remix.ethereum.org. So, after starting ganache-cli without any extra parameters on standard port 8545, I connect on Remix via web3 Provider http://127.0.0.1:8545 and my accounts show up, as displayed by Ganache.

This is the contract I want to deploy:

pragma solidity ^0.4.20;

contract Test {

    uint[4] public arr; // [0,0,0,0]
    event TestLog(string logmessage);

    function Test() public {
        arr[0] = 1; // [1,0,0,0]
    }

    function checkArray() public {
        if(arr[0] == 1) { // arr == [1,?,?,?]
            arr[1] = 1;
            arr[0] = 0; // switch values [0,1,0,0]
        }
        TestLog("some log");
    }

}

It works fine with the in-built Javascript VM in Remix: [vm] from:0xca3...a733c, to:Test.checkArray() 0x692...77b3a, value:0 wei, data:0x7b3...f7296, 1 logs, hash:0xa6f...87209

If i try to run the checkArray function in Remix connected to ganache via web3 Provider, I get an transact to Test.checkArray errored: VM Exception while processing transaction: out of gas error.

What am I doing wrong here? Bumping up gasLimit with ganache-cli -l 5000000did not help, as well as even higher values and a follow up test with a very small gasPrice and high gas limit. Is it a Remix problem setting wrong gas limits on the Remix website when building the transaction? I also tried it on a private geth node with the same result: out of gas...

Any help gladly appreciated!

1

This seems to be a testrpc/ganache bug. The line making trouble is setting respectively resetting the array value at position 0 to zero arr[0] = 0;.

I used Rinkeby with the same contract and it works as initially expected. You may test it here: https://rinkeby.etherscan.io/address/0x78aC7667BdeDC3b1CdF43611AdF7a88e05b600F5

As this is some very basic functionality, I'm left to say: what the fuck?

0

In my opinion, setting arr[0] is incorrect because that element doesn't exist. It is/was always walking off the end of the array. Use arr.push(1) to extend the length of the array.

Hope it helps.

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.