Book Image

Mastering Blockchain Programming with Solidity

By : Jitendra Chittoda
Book Image

Mastering Blockchain Programming with Solidity

By: Jitendra Chittoda

Overview of this book

Solidity is among the most popular and contract-oriented programming languages used for writing decentralized applications (DApps) on Ethereum blockchain. If you’re looking to perfect your skills in writing professional-grade smart contracts using Solidity, this book can help. You will get started with a detailed introduction to blockchain, smart contracts, and Ethereum, while also gaining useful insights into the Solidity programming language. A dedicated section will then take you through the different Ethereum Request for Comments (ERC) standards, including ERC-20, ERC-223, and ERC-721, and demonstrate how you can choose among these standards while writing smart contracts. As you approach later chapters, you will cover the different smart contracts available for use in libraries such as OpenZeppelin. You’ll also learn to use different open source tools to test, review and improve the quality of your code and make it production-ready. Toward the end of this book, you’ll get to grips with techniques such as adding security to smart contracts, and gain insights into various security considerations. By the end of this book, you will have the skills you need to write secure, production-ready smart contracts in Solidity from scratch for decentralized applications on Ethereum blockchain.
Table of Contents (21 chapters)
Free Chapter
1
Section 1: Getting Started with Blockchain, Ethereum, and Solidity
5
Section 2: Deep Dive into Development Tools
9
Section 3: Mastering ERC Standards and Libraries
16
Section 4: Design Patterns and Best Practices

Gas economic patterns

Ether has an economic value and is being traded on exchanges. Ether is used as a crypto fuel to execute transactions on the Ethereum blockchain. In Solidity, each function execution consumes gas. The gas consumed is always paid in ether from the transaction initiator to the block miner. Higher gas consumption by a contract would need more ether; similarly, lower gas consumption would incur a lower amount of ether, and thus lowers the execution cost. Hence, it is always preferred to write the contract in such a way that it can consume the least amount of gas possible for the processing of each transaction.

One possible way to reduce gas consumption is to always deploy the contract with an enabled optimization flag. This process optimizes the EVM bytecode, which then consumes less gas.

We will discuss some of the patterns that can be used to reduce the...