Chapter 6. Writing more complex smart contracts

 

This chapter covers

  • Building a crowdsale management Dapp showing how to structure complex contracts
  • Extending the crowdsale management Dapp through single and multiple inheritance

The purpose of the previous chapter was to give you a foundation in Solidity, so I focused mainly on the basic syntax that the language offers. In the next two chapters, I’ll introduce more advanced object-oriented (OO) features. I’ll start with inheritance in chapter 6 and follow with abstract contracts and interfaces in chapter 7. These OO features allow you to reduce code duplication and make your contracts more composable.

The contract side of real-world Dapps is generally more complex than the single-contract Dapp you’ve seen so far with SimpleCoin. They often span many contracts interacting with each other, with each contract being a concrete instance of a potentially complex inheritance structure. In this chapter, I’ll help you build Simple-Crowdsale, a basic crowdsale management Dapp. A crowdsale is the process through which investors fund a Dapp by buying tokens issued by the organization that’s developing it. This sample application will give you an idea of how complex the smart contract layer of a realistic Dapp can be and how inheritance, abstract classes, and interfaces can help you model it appropriately.

6.1. Introducing SimpleCrowdsale, a crowdsale contract

6.2. Extending functionality with inheritance

Summary

sitemap