I got this error in the terminal while running the npx Hardhat compile I've tried looking at the other examples of the error Stack Exchange but none have been able to provide a fix for my issue.

 ParserError: Expected '(' but got identifier
   --> contracts/MyToken.sol:122:14:
122 |     function freezeAddress(address _addr) public onlyOwner() {
    |              ^^^^^^^^^^^^^
Error HH600: Compilation failed

here is the code snippet

   mapping (address => bool) frozen;

    function freezeAddress(address _addr) public onlyOwner() {
      frozen[_addr] = true;

    function isFrozen(address _addr) public view returns (bool) {
      return frozen[_addr];

    function unfreezeAddress(address _addr) public onlyOwner() {
      frozen[_addr] = false;

  mapping (address => address[]) public transactionHistory;

  function freezeAddressAndAssociatedAddresses(address _addr) public onlyOwner {
    frozen[_addr] = true;
    for (uint i = 0; i < transactionHistory[_addr].length; i++) {
      address associatedAddress = transactionHistory[_addr][i];
      frozen[associatedAddress] = true;
  • This is very strange. Can you recheck the opening and closing brackets for theh contract and each function. May 20 at 6:12
  • I dont know but is onlyOwner() causing the problem? Try and use onlyOwner without ().
    – norym
    May 20 at 15:02
  • @norym That didn't work I think it might have something to do with freezeAddress? But I am not entirely sure how to move on from there May 20 at 19:11
  • @ZartajAfser that actually worked thank you but now im getting same error on ParserError: Expected '(' but got identifier --> contracts/MyToken.sol:148:14: | 148 | function transfer(address _to, uint256 _value) public returns (bool) { | ^^^^^^^^ Error HH600: Compilation failed May 20 at 19:19
  • I see. Can you just paste the whole contract in the code block, I'll try to compile it and let you know what's the problem. May 21 at 5:54


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.