Last active
March 21, 2022 00:30
-
-
Save MCarlomagno/22a5eded98fd637011c38700e686328d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.7.0 <0.9.0; | |
contract Chat { | |
// ... | |
// We can use an autoincremental id for each new message. | |
uint lastMessageId; | |
function sendMessage(string _text) public { | |
// increments id and sends message. | |
lastMessageId++; | |
sendMessageEvent(lastMessageId, msg.sender, _text); | |
} | |
} |
Hi Nicolas! Yes, you are totally right, I refactored the variable name and I forgot to replace it in that line. Anyway, the full function code seems to be right. Thanks a lot for the correction :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't understand one thing:
When
sendMessage()
function is called then thelastMessageId
is incremented which I suppose it's used bysendMessageEvent
event. But instead a different value (messageIdCounter
) is used.BTW - I got this code from the Blockchain chat server application written in Solidity article. Thanks for sharing!