Solidity Programming Essentials: A guide to building smart contracts and tokens using the widely used Solidity language, 2nd Edition
- Length: 412 pages
- Edition: 2
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2022-06-10
- ISBN-10: 1803231181
- ISBN-13: 9781803231181
- Sales Rank: #2024690 (See Top 100 Books)
A comprehensive guide sprinkled with lots of hands-on code samples to get you up and running with Solidity and writing your smart contracts on Blockchain and Ethereum
Key Features
- Learn proven smart contract implementation challenges and solve them using Solidity
- Go deeper into Solidity to write effective upgradable and maintainable smart contracts using best practices
- Get to grips with the latest version of Solidity with updated codes and examples
Book Description
Solidity is a high-level language for writing smart contracts, and the syntax has large similarities with JavaScript, thereby making it easier for developers to learn, design, compile, and deploy smart contracts on large blockchain ecosystems including Ethereum and Polygon among others. This book guides you in understanding Solidity programming from scratch.
The book starts with step-by-step instructions for the installation of multiple tools and private blockchain, along with foundational concepts such as variables, data types, and programming constructs. You’ll then explore contracts based on an object-oriented paradigm, including the usage of constructors, interfaces, libraries, and abstract contracts. The following chapters help you get to grips with testing and debugging smart contracts. As you advance, you’ll learn about advanced concepts like assembly programming, advanced interfaces, usage of recovery, and error handling using try-catch blocks. You’ll also explore multiple design patterns for smart contracts alongside developing secure smart contracts, as well as gain a solid understanding of writing upgradable smart concepts and data modeling. Finally, you’ll discover how to create your own ERC20 and NFT tokens from scratch.
By the end of this book, you will be able to write, deploy, and test smart contracts in Ethereum.
What you will learn
- Write efficient, effective, and secure smart contracts
- Code, compile, and test smart contracts in an object-oriented way
- Implement assembly code in Solidity
- Adopt upgradable and haltable ownership and security design patterns
- Understand exception handling and debugging in Solidity
- Create new ERC20 and NFT tokens from the ground up
Who this book is for
This Ethereum book is primarily aimed at beginners who want to get started with Solidity Programming for developing an Ethereum smart contract. No prior knowledge of EVM is required, but knowing the basics of any programming language will help you follow along.
Solidity Programming Essentials Second Edition Contributors About the author About the reviewer Preface Who this book is for What this book covers To get the most out of this book Download the example code files Download the color images Conventions used Get in touch Share Your Thoughts Part 1: The Fundamentals of Solidity and Ethereum Chapter 1: An Introduction to Blockchain, Ethereum, and Smart Contracts Technical requirements What is a blockchain? The need for blockchain Understanding cryptography Hashing Digital signatures Reviewing blockchain and Ethereum architecture Relationship between blocks How transactions and blocks are related to each other Consensus Proof of work Proof of stake Ethereum nodes EVM Mining nodes Ethereum validators Ethereum accounts Externally owned accounts Contract accounts Ether, gas, and transactions Blocks An end-to-end transaction Smart contract Writing smart contracts The internals of smart contract deployment Summary Questions Further reading Chapter 2: Installing Ethereum and Solidity Technical requirements Ethereum networks Main network Test network Private network Consortium network Installing and configuring Geth Installing Geth on macOS Installing Geth on Windows Creating a private network Installing Ganache Installing the Solidity compiler Installing the web3 framework Installing and using MetaMask Summary Questions Further reading Chapter 3: Introducing Solidity Technical requirements The Ethereum Virtual Machine Understanding Solidity and Solidity files Pragma Comments Importing Solidity code Contracts The structure of a contract State variables Structure Modifiers Events Enumeration Functions Exploring data types in Solidity Value types Reference types Storage and memory data locations Rule one Rule two Rule three Rule four Rule five Rule six Rule seven Rule eight Using literals Understanding integers Understanding Boolean The byte data type Understanding arrays Fixed arrays Dynamic arrays Special arrays Array properties Knowing more about the structure of an array Enumerations Understanding the address data type Working with mappings Summary Questions Further reading Chapter 4: Global Variables and Functions Technical requirements Variable scoping Type conversion Implicit conversion Explicit conversion Block and transaction global variables Transaction- and message-related global variables The difference between tx.origin and msg.sender Cryptographic global variables Address global variables Contract global variables Recovering addresses using ecrecover Summary Questions Further reading Chapter 5: Expressions and Control Structures Technical requirements Understanding Solidity expressions Understanding the if and if...else decision controls Exploring while loops Understanding the do...while loop Understanding breaks Understanding continue Understanding return Summary Questions Further reading Part 2: Writing Robust Smart Contracts Chapter 6: Writing Smart Contracts Technical requirements Smart contracts Writing a smart contract Creating contracts Using the new keyword Using the address of a contract Contract constructor Contract composition Inheritance Single inheritance Multilevel inheritance Hierarchical inheritance Multiple inheritance Encapsulation Polymorphism Function polymorphism Contract polymorphism Method overriding Abstract contracts Interfaces Advanced interfaces Library Importing a library Summary Questions Further reading Chapter 7: Solidity Functions, Modifiers, and Fallbacks Technical requirements Function input and output Modifiers Visibility scope View, constant, and pure functions Address-related functions The address send method The address transfer method The address call method The address callcode method The address delegatecall method The address staticcall method The fallback and receive functions Summary Questions Further reading Chapter 8: Exceptions, Events, and Logging Technical requirements Exception handling Require Assert Revert Try-catch in Solidity Events and logging Summary Questions Further reading Chapter 9: Basics of Truffle and Unit Testing Technical requirements Application development life cycle management Introducing Truffle Development with Truffle Testing with Truffle Interactively working with Truffle Summary Questions Further reading Chapter 10: Debugging Contracts Technical requirements Overview of debugging The Remix editor Using events Using a block explorer Summary Questions Further reading Part 3: Advanced Smart Contracts Chapter 11: Assembly Programming Technical requirements An introduction to Solidity and its advantages Getting started with Assembly programming Scopes and blocks Returning values Working with memory slots Working with storage slots Calling contract functions Determining contract addresses Summary Questions Further reading Chapter 12: Upgradable Smart Contracts Technical requirements Learning what constitutes upgradability Understanding dependency injection Providing instance addresses during contract deployment Providing instance addresses following contract deployment Reviewing problematic smart contracts Implementing simple solutions with inheritance Implementing simple solutions with composition Implementing advanced solutions using proxy contracts Writing upgradable contracts with upgradable storage Summary Questions Further reading Chapter 13: Writing Secure Contracts Technical requirements SafeMath and under/overflow attacks Reentrancy attack The EtherPot contract The Hacker contract Solutions to the reentrancy problem Security best practices Summary Questions Further reading Chapter 14: Writing Token Contracts Technical requirements Introducing tokens ERC20 Tokens ERC20 standard ERC20 functionality ERC20 events Non-fungible tokens ERC721 The ERC721 implementation EIP223 ERC165 Summary Questions Further reading Chapter 15: Solidity Design Patterns Technical requirements Introducing entity modeling Ethereum storage Data types in Ethereum Understanding data modeling in Solidity Nested versus reference fields Exploring types of relationships One-to-one relationships One-to-many relationships Many-to-many relationships Reviewing the rules for embedding structures Data cohesion Out-of-bounds nested structure Static data within a nested structure The nested structure will not change in the near future Containment relationship Having few relationships Performing data modeling using an example Structures State variables Adding Employees Retrieving a single Employees record Updating Employees Retrieving all Employees Ownership in smart contracts Exploring ownership in Solidity Modifier Establishing ownership of a smart contract Multiownership Transfer of ownership MultiSig contracts Transfer of the ownership of assets within a smart contract Stoppable/haltable smart contract pattern Summary Questions Further reading Assessments Chapter 1, Introduction to Blockchain, Ethereum, and Smart Contracts Chapter 2, Installing Ethereum and Solidity Chapter 3, Introducing Solidity Chapter 4, Global Variables and Functions Chapter 5, Expressions and Control Structures Chapter 6, Writing Smart Contracts Chapter 7, Functions, Modifiers, and Fallbacks Chapter 8, Exceptions, Events, and Logging Chapter 9, Truffle Basics and Unit Testing Chapter 10, Debugging Contracts Chapter 11, Assembly Programming Chapter 12, Upgradable Smart Contracts Chapter 13, Writing Secure Contracts Chapter 14, Writing Token Contracts Chapter 15, Solidity Design Patterns Why subscribe? Other Books You May Enjoy Packt is searching for authors like you Share Your Thoughts
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: Solidity Programming Essentials: A guide to building smart contracts and tokens using the widely used Solidity language, 2nd Edition
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.