Hi @JP-C,
The code you’ve posted should work and meet the main assignment objectives, but can you also post the top few lines of code in your bank.sol file (up to the contract header) so we can see how it inherits the functionality it needs? Bank is the contract we want to deploy, and ultimately destroy, so even if you haven’t made any changes to the body of the contract, you still need to demonstrate how you’ve coded the inheritance relationship.
A couple of observations …
(1)
In order to transfer the remaining Bank contract balance to the contract owner’s external address, you don’t need to include this line of code in your close() function in Destroyable. It will achieve the desired result, and from a technical point of view it is well coded * (except, see the note below). However, as well as destroying the Bank contract, selfdestruct
will also automatically transfer the remaining contract balance to the payable address argument it is called with (in our case, the contract owner’s address). This is all part of the pre-defined selfdestruct
functionality. So, if you remove this additional line of code from your close() function, you will see that calling this function still produces exactly the same results.
* To call the totalBalance() function as the transfer
method’s argument, you don’t need the this
keyword. You can just use a standard function call: msg.sender.transfer(totalBalance());
(2) Keeping the totalBalance() function, to retrieve the total Bank contract address balance at any time, is still a good idea. It will successfully return the correct contract balance, but the contract address doesn’t need to be converted to a payable address, because it’s not receiving any ether. The function is only referencing the address’s balance property, to read and return it. So you can remove payable()
as follows …
function totalBalance() public view returns(uint) {
return address(this).balance;
}
Let me know if anything is unclear, or if you have any questions