Hi @moise,
Your transfer event and corresponding emit statement are both well coded. The emit statement is in the correct position in the transfer() function body and will log appropriate data when the transfer() function is successfully executed
Your additional modifiers (checkBalance and noReentrance) and their implementation in the function header are also, on the whole, well coded and provide the necessary input restrictions. However, the following improvements can be made:
-
Your checkBalance condition will evaluate to false, and the transfer transaction will revert, if the sender tries to transfer their whole balance. But this should be allowed. Only amounts greater (and not equal to) their balance should be prevented. A simple modification to the comparison operator will fix this.
-
If input values need to be checked, this should be the first operation which is performed during the execution of a function; and require() statements should be executed as early as possible so that, if one fails, the amount of gas refunded is maximised. As well as the gas cost of executing the require statement which fails, any gas consumed before revert is triggered will also not be refunded. The transfer amount, and the sender and recipient addresses are first input when the main transfer() function is called externally, and so the two modifiers should be applied to that function header, instead of the header of the _transfer() helper function.
The term re-entrancy refers to a type of attack, which you will learn about in the courses after this one. I would, therefore, change the name of your noReentrance modifier to something else, so itâs not misinterpreted as being code implemented to prevent a re-entrancy attack.
I would also recommend leaving a space between your operators and their operands, and also after the commas separating your arguments and parameter definitions. This will make your code clearer and easier to read, especially as you like to use a lot of underscores in your identifiers e.g.
balance[_recipient] += _amount;
â instead of âŚ
emit transfertDone(_amount, msg.sender, _recipient);
â instead of âŚ
â and
function transfert(address _recipient, uint _amount) public { ... }
â instead of âŚ
Let me know if anything is unclear, or if you have any questions.