Search code examples
ethereumsoliditysmartcontracts

Return string in solidity 0.5.0. Data location must be "memory" for return parameter in function


How to return string in 0.5.0 solidity compiler version?

contract Test {
    string public text = 'show me';
    function  test() public view returns (string) {
        return text;
    }
}

I got error message:

TypeError: Data location must be "memory" for return parameter in function, but none was given.

Solution

  • Just need to add memory after string, like this:

    function test() public view returns (string memory) {
    

    Another changes: https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html#interoperability