Nice solution @JJ_FX
The additional admin state variable, constructor and modifier you’ve added, which only allows the deployer of the contract (admin) to add new users and update their balances, also makes sense Your modifier works wherever its declaration is positioned within the contract body, but I think the overall structure and functionality of your code will be clearer if the declaration appears before its implementation in the functions. When reading the code of a contract, it makes more intuitive sense to have seen the modifier’s actual code before seeing references to it in the function headers.
Even though the initial idea of this assignment is to update the existing balance by replacing it with the new one, I actually think that it makes more sense to do what you have done, and add an amount to the existing balance using the addition assignment operator +=
(instead of the assignment operator =
). However, if you add to , instead of replacing , the existing balance, I think your code would be clearer and more readable if you also change the name of the balance
parameter to amount
, because you are adding an amount to the balance, rather than replacing it with a new balance .
Let me know if you have any questions