I am facing difficulties changing the length of a global 2D storage array.

It seems to be working correctly on Remix IDE, but when I try to test it on ganache-cli (formerly known as testrpc) - either via truffle test (Javascript) or via web3 (Python) - it fails to work.

By "fail to work", I mean I can set the length of the array, but when I retrieve it - I always get 0.

Here is a minimal piece of code which reproduces the problem:

pragma solidity ^0.4.11;

contract Test {
    struct Data {
        uint256 a;
        uint256 b;
        uint256 c;
        uint256 d;
        uint256 e;
        uint256 f;

    Data[][] private lists;

    function Test() public {

    function setLength(uint256 length) public {
        lists.length = length;

    function getLength() public constant returns (uint256) {
        return lists.length;

As you can see, I am using a storage array.

Any ideas will be highly appreciated.

Thank you!!!

1 Answer 1


This problem stems not from changing the length of an array, but rather from changing the state of the contract (i.e., changing a global variable).

So far, I have only tested functions which do not change the state of the contract - either via truffle (Javascript) or via web3 (Python).

In both cases, I have been using call in order to execute the Solidity function.

For functions which do change the state of the contract, one needs to use transact instead.

The full explanation can be found in this answer.

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.