The smart contract is a significant component of the blockchain technology that has been instrumental in transforming a cryptocurrency framework into a trust framework enabling broad range of decentralized applications. This chapter provides details on the concept, design, and development of a smart contract, and also examines the power of executable code on the blockchain.
Structurally, a smart contract is a standalone piece of code similar to a class in an object-oriented program. It is a deployable module of code with data and functions. Functions serve the specific purposes of verification, validation, and enabling recording of the messages sent. A contract in the real world involves rules, conditions, laws, regulations to be enforced, criteria, contingencies, and items for provenance such as dates and signatures. Similarly, the smart contract in a blockchain context implements the contract rules for solving a decentralized problem. It functions as a rules engine as well as a gatekeeper, so understandably, the smart contract design requires careful consideration. Following is an explanation of a smart contract modified to include the code aspects.