2
votes

I am practicing my Solidity skills and while I did expect to get an error, I did not expect this error

TypeError: This type is only supported in the new experimental ABI encoder. Use "pragma experimental ABIEncoderV2;" to enable the feature. function getArray() public view returns (string[]) {

This is my code in Remix:

pragma solidity ^0.4.17;

contract Test {
    string[] public myArray;

    function Test() public {
        myArray.push("hola");
    }

    function getArray() public view returns (string[]) {
        return myArray;
    }
}

What gives here?

Is this because the standard ABI does not support dynamic nested arrays?

I just want to confirm my understanding of the error. It is telling me that arbitrarily nested arrays in function arguments and return values are not supported in my current version but in the new experimental ABI encoder, is this what its saying?

1

1 Answers

3
votes

That's because of string[].

Yes it's because dynamic nested arrays are not supported yet, it's still experimental. You can enable the feature by adding pragma experimental ABIEncoderV2; on top of the source code.

web3 package just started to support it in the latest web3 1.0.0-beta36 release. Truffle still depends on a previous web3 version so you need to wait a bit (around a month) if you want to test your contract using Truffle.