0

When attempting to compile the following contract I am receiving the following error: InternalCompilerError: Stack too deep, try using fewer variables. How can I fix this?I want the getPerson function to emit all the data from AddPerson. If I reduce the variables in the functions,how do I achieve that?

pragma solidity >=0.5.0 <0.7.0;

contract PersonData {
    function AddPerson(
        string memory fullName,
        string memory residentialAddress,
        string memory sex,
        uint age,
        uint weight,
        uint height,
        string memory eyeColor,
        string memory hairColor,
        string memory complexion,
        string memory maritalStatus,
        string memory educationalLevel,
        string memory occupation,
        string memory placeOfBirth,
        string memory nationality
    )
        public
        returns (bool)
    {
        personCounter = personCounter + 1;
        Person memory person; //Person struct gives inbuilt method which is called person
        person.fullName = fullName;
        person.residentialAddress = residentialAddress;
        person.sex = sex;
        person.eyeColor = eyeColor;
        person.hairColor = hairColor;
        person.complexion = complexion;
        person.maritalStatus = maritalStatus;
        person.educationalLevel = educationalLevel;
        person.occupation = occupation;
        person.placeOfBirth = placeOfBirth;
        person.nationality = nationality;
        persons[msg.sender] = person;

        return true;
    }

    function getPerson(address _personToGet) public view returns (
        string memory fullName,
        string memory residentialAddress,
        string memory sex,
        uint age,
        uint weight,
        uint height,
        string memory eyeColor,
        string memory hairColor,
        string memory complexion,
        string memory maritalStatus,
        string memory educationalLevel,
        string memory occupation,
        string memory placeOfBirth,
        string memory nationality
    ) {
        fullName = persons[_personToGet].fullName;
        residentialAddress = persons[_personToGet].residentialAddress;
        sex = persons[_personToGet].sex;
        age = persons[_personToGet].age;
        weight = persons[_personToGet].weight;
        height = persons[_personToGet].height;
        eyeColor = persons[_personToGet].eyeColor;
        hairColor = persons[_personToGet].hairColor;
        complexion = persons[_personToGet].complexion;
        maritalStatus = persons[_personToGet].maritalStatus;
        educationalLevel = persons[_personToGet].educationalLevel;
        occupation = persons[_personToGet].occupation;
        placeOfBirth = persons[_personToGet].placeOfBirth;
        nationality = persons[_personToGet].nationality;
    }
}
  • So what's your question? The error message seems pretty clear. Too many local variables used (in your case - way too many). – goodvibration Dec 26 '19 at 11:24
  • I want the getPerson function to return all the data captured in AddNewPersonData.If I split the function can I still achieve that? I need help on how – Jaylukmann Dec 26 '19 at 12:34
  • Please explain that as part of the question, and include ONLY the relevant information (not your entire contract, unless absolutely necessary). – goodvibration Dec 26 '19 at 12:42
  • You are way over budget. Variable-length fields, like string count for 2 arguments (because of length) and the max number of arguments is 16 (or 8 strings). In general, this sort of interface looks like a substitute for a database which is not a good way to think about ethereum contracts. – Rob Hitchens Dec 27 '19 at 1:33

Browse other questions tagged or ask your own question.