0
pragma solidity ^0.4.25;

contract Inbox {
    string  public message;


    constructor Inbox(string initialMessage) public {
        message = initialMessage;
    } 

    function setMessage(string newMsg) public {
        message = newMsg;
    }

    function getMessage() public view returns(string){
        return message;
    }
}

1 Answer 1

1

The error message "Expected '(' but got identifier constructor Inbox(string initialMessage) public {" indicates that there is a syntax error in your code. The issue is likely with the line where you define the constructor function for your contract.

In Solidity, the keyword "constructor" must be followed by a pair of parentheses, even if the constructor does not take any arguments. This is because the parentheses are used to enclose the list of arguments that the constructor accepts.

In your code, you are missing the opening parenthesis after the "constructor" keyword. To fix this error, you can add an opening parenthesis after the keyword, like this:

contract Inbox {
  string public message;

  constructor(string initialMessage) public {
    message = initialMessage;
  }

  function setMessage(string newMsg) public {
    message = newMsg;
  }

  function getMessage() public view returns(string){
    return message;
  }
}

After making this change, your code should be able to compile without any errors. I would also recommend double-checking your code against the Solidity language specification to ensure that it follows the correct syntax and is properly formatted.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.