August 2019
Intermediate to advanced
486 pages
13h 52m
English
The mortal pattern allows a contract to be destroyed from the Ethereum blockchain. As you know, a Solidity contract can be destroyed using a selfdestruct() function call in the contract. You can have this function call in your contract to allow it to be destroyed once the contract job is over. Once a contract is destroyed, the contract states would not remain on the blockchain, and if there are any ethers present in the contract, it would be sent to an address passed to the selfdestruct() function as argument.
As you can see in the following sample code, there is a kill() function. Only the owner of the contract can call this function:
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";contract Mortal is Ownable ...