Search code examples
soliditysmartcontractsevm

ParserError: Expected '{' but got 'memory'


Am using pragma solidity >=0.7.0 <0.9.0;.

Line 42 with the below function:

function addXtoAccName( address _accNumber, string _xtoName ) public memory {
        accounts[_accNumber].xtoDisplayName = _xtoName;
        accounts[_accNumber].xtoAccNumber = _accNumber;
}

is causing this error message:

ParserError: Expected '{' but 
got 'memory'
:
:
42 | function addXtoAccName(
address _accNumber, string 
_xtoName ) public membory {
| ^^^^^^

Can someone explain what am I doing wrong on line 42?


Solution

  • Your code uses the memory keyword in the modifier section of the function definition, where it doesn't belong. Also, it's missing the data location for the string argument. All reference types (including string) need to define their data location.

    So it seems that you just misplaced the memory keyword.

    Note just in case if you were aiming to intentionally use a modifier named memory: It's a reserved keyword, so it's not possible to use a modifier with this name.


    Solution: Move the memory keyword after the string:

    function addXtoAccName( address _accNumber, string memory _xtoName ) public {