Skip to Content
Mastering Blockchain Programming with Solidity
book

Mastering Blockchain Programming with Solidity

by Jitendra Chittoda
August 2019
Intermediate to advanced
486 pages
13h 52m
English
Packt Publishing
Content preview from Mastering Blockchain Programming with Solidity

Mortal pattern

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood
Complete Cryptocurrency and Blockchain Course | Learn Solidity

Complete Cryptocurrency and Blockchain Course | Learn Solidity

Ravinder Deol, Codestars By Rob Percival, Thomas Wiesner

Publisher Resources

ISBN: 9781839218262Supplemental Content