1

I've seen the other StackExchange errors but it didn't help me.

Untitleded.sol:5:77: ParserError: Expected type name function sendmessage(string message) view public returns(string message, memory) { ^----^

This is the full code:

pragma solidity 0.5.1;

contract chat{
   event sendmessage(string message);
   function sendmessage(string message) view public returns(string message, memory) {
       emit sendmessage(message);
       return message;
   }
}

How can I fix this?

1 Answer 1

0

There are a few issues with your code. The fixed code block is below.

  1. You need to use memory or calldata when declaring strings
  2. Your event name and your function name cannot match
  3. Since you are emitting an event, you need to remove the view modifier
  4. The syntax of your returns statement is incorrect
  5. (Styling) The name of the contract should be PascalCase (e.g., Chat)
  6. (Styling) The name of your event should be PascalCase (e.g., SendMessage)
pragma solidity 0.5.1;

contract chat{
   event SendMessage(string message);
   
   function sendmessage(string memory message) public returns(string memory) {
       emit SendMessage(message);
       return message;
   }
}

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.