Overall, a very nice solution @gaio
A few commentsâŚ
(1) Your inheritance structure works, but it is not multi-level inheritance. We can streamline the inheritance structure by having Bank explicitly inherit Destroyable only, because it will inherit Ownable implicitly via Destroyable. This will give you a multi-level inheritance structure.
(2)
Exactly right You are right to remove the
owner
state variable from Bank, because this is now inherited from Ownable.
This means that the constructor is also now redundant in Bank and should also be removed to avoid unnecessary code duplication (which is one of main reasons for using inheritance). On deployment, the constructor in Ownable assigns the contract ownerâs address to the owner
state variable, and so Bank, as well as Destroyable, can both access the ownerâs address by referencing owner
(which youâve done appropriately without a constructor in Destroyable).
(3) You are missing the require statement in withdraw(), which is an essential check to ensure the caller has enough ether to cover the requested amount. You could either add it directly to the function body, or implement your enoughBalance modifier like @thecil explained here. The advantage of using the modifier is that it can also be used in transferTo(), which would avoid code duplication. However, if youâre not going to use your modifiers, then you should comment our their code entirely (not just their bodies).
(4) Have a look at this post which explains the importance of the order of the statements within your withdraw function body.
(5) If you want to import Buidlerâs console.log
then you need to correct the spelling of âbuidlerâ in the import statement. Have you downloaded the Buidler EVM with npm, using the instructions in the article you linked to? I would probably wait until youâve completed the 201 course before you try experimenting with it. In the 201 course youâre going to use Truffle and the local Ethereum network Ganache. From reading the article it seems the Builder EVM is an alternative to Ganache, so I would probably avoid using both to start with, which could lead to confusionâŚ
Let me know if anything is unclear, or if you have any further questions