Solidity, used for writing smart contracts on blockchain platforms like Celo, supports a variety of powerful features. One of these is the
selfdestruct function, which enables a contract to delete itself and forward its remaining CELO to a specified address. In this challenge, you will construct a contract that can self-destruct under certain conditions.
Develop a smart contract that has a self-destruct feature with the following requirements:
- The contract should allow only the contract creator to self-destruct the contract.
- The contract should hold a balance.
- On self-destruction, the contract’s balance should be sent to a specific beneficiary address provided by the contract creator.
- Before self-destruction, the contract should allow the contract creator to change the beneficiary address.
- Use the
selfdestructfunction in Solidity to destroy the contract.
msg.senderto restrict the self-destruction functionality to the contract creator.
- Store the contract creator’s address and the beneficiary address in state variables.
- Use a
modifierto create a function that only the contract creator can call to change the beneficiary address.
- Correctness: The contract should compile without errors and fulfill all the requirements.
- Readability: The contract should be well-documented, with comments explaining the code.
- Testability: You should also provide examples of how to test each function of the contract.
Keep in mind, using
selfdestruct should be done with caution, as it can make a contract completely unusable and cannot be reversed.
For a comprehensive understanding of Celo smart contracts, Solidity, and the
selfdestruct function, please refer to the Celo and Solidity tutorials.
Please reply with a link to your PR on GitHub - celo-academy/Build-a-Self-Destructing-Contract-in-Solidity-Coding-Challenge, including your self-destructing contract. Also, include any notes or comments you think are necessary to understand your design and choices. Lastly, provide a brief explanation about how each function of the contract should be tested.