15

If I try to define a function using an array of strings as an argument, solc gives me the following error:

Error: Internal type is not allowed for public or external functions.
    function test(string[] x){}
                  ^--------^

This works fine:

function test(int[] x){}

And so does this:

function  test(string[] x) private {}

Am I missing something obvious?

J-B
  • 8,941
  • 16
  • 46
  • 77
gellej
  • 480
  • 4
  • 8

2 Answers2

13

No, I don't believe so. As I understand it, Solidity doesn't have a built-in way yet to deserialize string arrays. It can cheat when the contract is passing an array it created itself to itself, which is why it works with private functions. But if you want to take string arrays from the outside, you're going to have to handle the serialization and deserialization from a string (or bytes) yourself. (E.g., concatenating fixed-length items, or using null characters as separators, or using commas, etc.)

ryepdx
  • 1,342
  • 8
  • 15
  • 1
    Perhaps this could be added to http://ethereum.stackexchange.com/q/305/42 since taking an array of strings is easily and commonly done in most other languages. – eth Feb 26 '16 at 23:05
4

You can convert the array elements to a byte string and then deserialize that byte string back to the array inside the function. Although this can prove to be quite expensive you can try it if you don't have a choice. You can follow this short article to serialize/deserialize any datatype in solidity.

Vaibhav Saini
  • 564
  • 4
  • 8