Hi @Maia,
It’s difficult for me to review your solution, because there are several things that don’t make any sense…
(1) It’s not clear whether both of your contracts are in the same file or separate files.
(2) You’ve imported the Ownable.sol file into itself!
Ownable is the parent contract and it doesn’t inherit another contract. We only need to import a file when the file it contains is being inherited.
(3) Your Bank contract inherits Destroyable, but where is your code for the Destroyable contract? If it’s in a separate file to Bank, then it also needs to be imported.
(4) Your Bank contract references the onlyOwner
modifier and the owner
variable, but both of these are in the Ownable contract, and according to your code as it currently stands (excluding Destroyable), Bank does not inherit Ownable.
Some additional observations…
a) The idea of the assignment is to place the selfdestruct() functionality within a separate contract called Destroyable, and for this to be inherited by Bank so that it is available when Bank is deployed, but without having to include the actual function code within Bank.
b) The function that contains selfdestruct() cannot also have the name selfdestruct
.
c) The address passed as an argument to the selfdestruct function must be payable
because this is the address that any ether remaining in the contract will be transferred to on destruction. You are passing owner
, which is defined as a non-payable address in your Ownable contract, and so needs to be converted to a payable address. There are a couple of alternative ways to do this.
To complete each coding assignment, and before moving on to the next lesson, you need to make sure (i) your code compiles without any errors (ii) your contract (in this case the child contract Bank) deploys successfully; and (iii) your deployed contract is able to perform all of the necessary transactions i.e. it does what you expect it to. In this assignment the aim is to be able to deploy Bank, perform some transactions, then destroy the Bank contract, transferring any remaining ether balance to the caller of the selfdestruct function (here, the contract owner).
If you want to benefit from this course, I would strongly recommend that you go back over the lessons, and take your time to understand, practise, think through and experiment with the code in each section before moving on to the next. You’ve moved through the course much too quickly and you haven’t given yourself time to properly understand the assignments or to reflect on your assignment feedback.
Here is a list of some learning and study activities, which you may find useful when working on assignments, and I think they could help you get more out of our programming courses…
- Have a look at other students’ posts in the relevant forum discussion topic, with their attempts, solutions, and the help, comments and feedback posted as replies. There are a lot of comments and explanations posted here. It’s well worth spending your time browsing and reading, not only to get help with the assignments, but also after finishing a section or particular assignment as a way to review what you’ve learnt, and to discover alternative coding solutions or answers.
- When you look at the assignment solutions, if they are different to your code, you should spend some time analysing and thinking about them. This is a really important stage in the learning process. You can learn a lot by working out what the solution code does and how it does it, and also how to go about “bridging the gap” from what you managed to do (or not) on your own. However, it’s important to remember that there are usually several different alternative approaches and solutions to these assignments, so if you’ve coded yours differently, but it still works, then it may well be valid. If you’re not sure, then post it here in the forum, and we’ll review it for you.
- Another good learning technique to use (after having already done the tasks described above) is to then try the assignment again from scratch without looking back at the solution (like a memory test). You can also try to do this after having left it for a certain period of time (say, the next day, then after a few days, then a week etc. etc.) This builds up longer-term retention. This is a good approach to take when reviewing a course you’ve already done, or earlier parts of the course you’re currently doing. Instead of just looking back at your solutions to the assignments, test yourself to see how many of them you can redo from scratch — only checking your previous code and notes, and rewatching the videos, if you need to remind yourself about certain things.
- Another important point to remember is that it can take some time before you fully understand all of the code in an assignment, so another good strategy is to come back and revisit an assignment , which you didn’t fully understand, after you’ve progressed a bit more through the course. You may well find that it’s much easier then.
- Don’t forget to do some research yourself on the Internet. Here is a link to a playlist from the YouTube channel Eat The Blocks . I’ve seen some of this guy’s videos myself and I think they are particularly helpful for learning Solidity. The videos are quite short and the explanations clearly explained and well demonstrated with clear examples. You’ll find that several of the videos in this playlist correspond to specific sections of this course, and so serve as an ideal starting point for your own further research.
https://www.youtube.com/playlist?list=PLbbtODcOYIoE0D6fschNU4rqtGFRpk3ea
- Finally … play around with the code, experiment , and try to come up with your own examples, no matter how basic, short or simple. Even by just making a few small changes and adaptations to the code presented in the course, any amount of personalisation that you are able to add to your code will help it to mean more to you, and will therefore help you to internalise it better.
Anyway, I hope this advice has been helpful. Just let me know if you have any questions 