How can I return a dynamic string array? I came across serialization and deserialization. How can I serialize and deserialize dynamic string array ?

pragma solidity ^0.5.0;

contract Abc{
    string[] st;

    function add(string memory newValue) public {

    // return st

Actually there is not support from solidity for returning an array of strings as described here:

Return dynamic array of string

You can fix it adopting this workaround described here:

Deserialize a string

| improve this answer | |

You need to use ABIEncoderV2:

pragma experimental ABIEncoderV2;

contract Foo {
  string [] private strings;

  function addString (string memory str) public {
    strings.push (str);

  function getStrings () public view returns (string [] memory) {
    return strings;

See documentation for details.

| improve this answer | |

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.