Book description
Discover the advanced features of Solidity that will help you write high-quality code and develop secure smart contracts with the latest ERC standards
Key Features
- Delve into Solidity and understand control structures, function calls, and variable scopes
- Explore tools for developing, testing, and debugging your blockchain applications
- Learn advanced design patterns and best practices for writing secure smart contracts
Book Description
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.
What you will learn
- Test and debug smart contracts with Truffle, Ganache, Remix, and MetaMask
- Gain insights into maintaining code quality with different tools
- Get up to speed with ERC standards such as ERC-20 and ERC-721
- Become adept at using design patterns while writing smart contracts
- Use MultiSignature (MultiSig) wallets and improve the security of contracts
- Use Oracle services to fetch information from outside the blockchain
Who this book is for
This book is for developers and data scientists who want to learn Ethereum, blockchain, and Solidity to write smart contracts and develop production-ready code. Basic knowledge of Solidity is assumed.
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- About Packt
- Foreword
- Contributors
- Preface
- Section 1: Getting Started with Blockchain, Ethereum, and Solidity
-
Introduction to Blockchain
-
Understanding blockchain
- Blockchain solves the double-spending problem
-
Properties of blockchain
- Distributed ledger
- Fault tolerance 
- Attack resistance
- Remove intermediaries
- Consensus protocol
- Faster settlement
- Lower transaction fees
- Transparency
- Immutability
- Irreversible transactions
- Trust in the network
- Availability
- Empower individuals
- Chronological order of transactions
- Timestamped
- Sealed with cryptography
- When to use blockchain
- When not to use blockchain
- Existing implementations of blockchain
- Introduction to Ethereum
- Smart contracts
- Summary
- Questions
-
Understanding blockchain
-
Getting Started with Solidity
- Introduction to the Solidity language
- Solidity data types
- Assigning variables with units
- Global special variables and functions
- Topics for self-study
- Summary
- Questions
- Further reading
- Control Structures and Contracts
- Section 2: Deep Dive into Development Tools
-
Learning MetaMask and Remix
- Technical requirements
- Using the MetaMask plugin
-
Using the Remix Solidity IDE
- The Remix IDE overview
- Compiler tools present under the Compile tab
- Understanding the Run tab
- Deploying a contract
- Initiating a transaction to execute the function
- Initiating a call to a view function and state variables
- Connecting the contract folder using remixd
- Setting up a local instance of the Remix IDE
- Using the blockchain explorer at etherscan.io
- Ethereum wallet software
- Using myetherwallet.com
- Summary
- Questions
- Using Ganache and the Truffle Framework
- Taking Advantage of Code Quality Tools
- Section 3: Mastering ERC Standards and Libraries
-
ERC20 Token Standard
- Technical requirements
- Overview of the ERC20 token standard
- ERC20 standard API
- ERC20 implementation
- Events
- Optional functions
- Advanced functions
- Summary
- Questions
-
ERC721 Non-Fungible Token Standard
- Technical requirements
- Overview of the ERC721 NFT standard
- The ERC721 NFT standard API interface
-
Understanding the ERC721 implementation
- ERC721 inherits from IERC721 and ERC165
-
Understanding ERC721 state variables
- Token owner mapping kept in _tokenOwner
- Approved address mapping kept in _tokenApprovals
- The number of tokens per owner kept in _ownedTokensCount
- Operator approvals kept in _operatorApprovals
- The ERC165 interface code for the ERC721, _INTERFACE_ID_ERC721
- The ERC165 interface code for the ERC721Receiver, _ERC721_RECEIVED
- The constructor of ERC721
- The balanceOf function
- The ownerOf function
- The approve function
- The getApproved function
- The setApprovalForAll function
- The isApprovedForAll function
- The transferFrom function
- The safeTransferFrom function
- Another safeTransferFrom function
- The _exists internal function
- The _isApprovedOrOwner internal function
- The _mint internal function
- The _burn internal function
- Another _burn internal function
- The _transferFrom internal function
- The _checkOnERC721Received internal function
- The _clearApproval internal function
- Events
- The ERC721TokenReceiver interface
- The ERC721Metadata interface
- The ERC721 enumerable
- The ERC721 full implementation
- Summary
- Questions
-
Deep Dive into the OpenZeppelin Library
- Technical requirements
- The OpenZeppelin project 
- Contract ownership
- Roles library
- Life cycle contracts
-
The ERC20 token standard library
- ERC20 interface – IERC20.sol
- Full ERC20 implementation using ERC20.sol
- Perform safe ERC20 function calls using SafeERC20.sol
- Create tokens with metadata using DetailedERC20.sol
- Create mintable tokens using ERC20Mintable.sol
- Allow token burning using ERC20Burnable.sol
- Create pausable tokens using ERC20Pausable.sol
- Math-related libraries
- Crowdsale
- Utility contracts
- Summary
- Questions
-
Using Multisig Wallets
- Technical requirements
- Understanding multisig wallets
- Benefits of using multisig wallets
- Precautions when using multisig wallets
- Learning ConsenSys multisig implementation
- Setting up your own multisig wallet
- Sending ETH from a multisig contract
- Controlling contracts with multisig
- Summary
- Questions
- Upgradable Contracts Using ZeppelinOS
- Building Your Own Token
- Section 4: Design Patterns and Best Practices
- Solidity Design Patterns
-
Tips, Tricks, and Security Best Practices
- Technical requirements
-
Smart contracts best practices
- Avoiding floating pragma
- Avoid sharing a secret on-chain
- Be careful while using loops
- Avoid using tx.origin for authorization
- The timestamp can be manipulated by miners
- Carefully making external function calls
- Rounding errors with division
- Using assert(), require(), and revert() properly
- Gas consumption
- Known attack patterns
- Security analysis tools
- Summary
- Questions
- Assessments
- Other Books You May Enjoy
Product information
- Title: Mastering Blockchain Programming with Solidity
- Author(s):
- Release date: August 2019
- Publisher(s): Packt Publishing
- ISBN: 9781839218262
You might also like
book
Blockchain and Ethereum Smart Contract Solution Development: Dapp Programming with Solidity
Build decentralized applications with smart contract programming. Following the curriculum from an active blockchain course taught …
book
Mastering Blockchain
The future will be increasingly distributed. As the publicity surrounding Bitcoin and blockchain has shown, distributed …
video
Complete Cryptocurrency & Blockchain Course | Learn Solidity
Welcome to one of the largest, most in-depth cryptocurrency and blockchain courses online! This course gives …
video
Getting Started with Blockchain and Cryptocurrency
3+ Hours of Video Instruction Overview In this course, participants learn what blockchain and cryptocurrency are, …