Hi @martina,
Your transfer event declaration and corresponding emit statement are both well coded and, once you correct a couple of issues in your transfer() function, your emit statement will log appropriate data when the transfer() function is successfully executed.
You need to add a call to the _transfer() helper function in the body of your main transfer() function, otherwise your emit statement won’t be executed! You also need to remove the last two lines of code from your transfer() function …
… otherwise you will be adjusting the sender and recipient balances for the transfer amount twice!
The assert() statement needs to check the sender’s individual balance after it has been adjusted for the transfer amount, and so the _transfer() helper function needs to be called before the assert() statement.
If you don’t use a separate helper function, and put all of the code associated with the transfer transaction in the main transfer() function (which is also a possible solution), then you’ll need to place your assert() statement after the individual balance adjustments, otherwise it will fail when it shouldn’t and prevent valid transfers from completing.
Your error message is wrong here. Users can transfer tokens — that’s the whole point of the function — but just not to themselves!
"Don't transfer tokens to yourself"
One final observation …
Whenever possible, an emit statement should be placed at the end of a function after all of the operations associated with the event have been performed, but before a return statement if there is one. And generally speaking, it’s probably also better to place an emit statement after an assert statement if there is one.
In addition, it’s better to emit the event at the end of the function which completes the transaction i.e. transfer() not _transfer().
Another important factor here is that if you emit an event in a helper function, you are restricting your ability to reuse that helper function. It will be more reuseable if we can call this same helper function from another function when we may not want to emit the same event — either a different one, or no event at all. That way we can reuse the helper function whenever we just want to implement its functionality (i.e. the operations, or computation, that it performs).
See if you can correct your code for these points. Just let me know if anything is unclear, or if you have any questions