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

Posted on Updated on

There are some updates in solidity 0.05.0 that Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and return variables. So the changes are as follows:

pragma solidity^0.5.0;

contract Contract {
    string public name;

    function Contracts(string passedName) public {
        name = passedName;
    }

    function setName(string newName) public {
        name = newName;

    }

}

To This:

pragma solidity^0.5.0;

contract Contract {
    string public name;

    function Contracts(string memory passedName) public {
        name = passedName;
    }

    function setName(string memory newName) public {
        name = newName;

    }

}

Leave a Reply

Your email address will not be published. Required fields are marked *