O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Solidity Programming Essentials

Book Description

Learn the most powerful and primary programming language for writing smart contracts and find out how to write, deploy, and test smart contracts in Ethereum.

About This Book
  • Get you up and running with Solidity Programming language
  • Build Ethereum Smart Contracts with Solidity as your scripting language
  • Learn to test and deploy the smart contract to your private Blockchain
Who This Book Is For

This book is for anyone who would like to get started with Solidity Programming for developing an Ethereum smart contract. No prior knowledge of EVM is required.

What You Will Learn
  • Learn the basics and foundational concepts of Solidity and Ethereum
  • Explore the Solidity language and its uniqueness in depth
  • Create new accounts and submit transactions to blockchain
  • Get to know the complete language in detail to write smart contracts
  • Learn about major tools to develop and deploy smart contracts
  • Write defensive code using exception handling and error checking
  • Understand Truffle basics and the debugging process
In Detail

Solidity is a contract-oriented language whose syntax is highly influenced by JavaScript, and is designed to compile code for the Ethereum Virtual Machine. Solidity Programming Essentials will be your guide to understanding Solidity programming to build smart contracts for Ethereum and blockchain from ground-up.

We begin with a brief run-through of blockchain, Ethereum, and their most important concepts or components. You will learn how to install all the necessary tools to write, test, and debug Solidity contracts on Ethereum. Then, you will explore the layout of a Solidity source file and work with the different data types. The next set of recipes will help you work with operators, control structures, and data structures while building your smart contracts. We take you through function calls, return types, function modifers, and recipes in object-oriented programming with Solidity. Learn all you can on event logging and exception handling, as well as testing and debugging smart contracts.

By the end of this book, you will be able to write, deploy, and test smart contracts in Ethereum. This book will bring forth the essence of writing contracts using Solidity and also help you develop Solidity skills in no time.

Style and approach

Solidity is a high-level programming language best understood using examples. After covering basic concepts of Ethereum and Solidity, programming constructs will be explained with help of examples. As chapters progress, deployment, usage and testing of contacts will form major aspect of the book. Troubleshooting and unit testing is an important exercise and skill to master this language will also be covered in this book.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Solidity Programming Essentials
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Introduction to Blockchain, Ethereum, and Smart Contracts
    1. What is a blockchain?
    2. Why blockchains?
    3. Cryptography
      1. Symmetric encryption and decryption
      2. Asymmetric encryption and decryption
      3. Hashing
      4. Digital signatures
    4. Ether
    5. Gas
    6. Blockchain and Ethereum architecture
      1. How are blocks related to each other?
      2. How are transactions and blocks related to each other?
    7. Ethereum nodes
      1. EVM
      2. Ethereum mining nodes
      3. How does mining work?
    8. Ethereum accounts
      1. Externally owned accounts
      2. Contract accounts
    9. Transactions
    10. Blocks
    11. An end-to-end transaction
    12. What is a contract?
    13. What is a smart contract?
      1. How to write smart contracts?
    14. How are contracts deployed?
    15. Summary
  7. Installing Ethereum and Solidity
    1. Ethereum networks
      1. Main network
      2. Test network
        1. Ropsten
        2. Rinkeby
        3. Kovan
      3. Private network
      4. Consortium network
    2. Geth
      1. Installing Geth on Windows
    3. Creating a private network
    4. ganache-cli
    5. Solidity compiler
    6. The web3 JavaScript library
    7. Mist wallet
    8. MetaMask
    9. Summary
  8. Introducing Solidity
    1. Ethereum Virtual Machine
    2. Solidity and Solidity files
      1. Pragma
      2. Comments
      3. The import statement
      4. Contracts
    3. Structure of a contract
      1. State variables
      2. Structure
      3. Modifiers
      4. Events
      5. Enumeration
      6. Functions
    4. Data types in Solidity
      1. Value types
        1. Passing by value
      2. Reference types
        1. Passing by reference
    5. Storage and memory data locations
      1. Rule 1
      2. Rule 2
      3. Rule 3
      4. Rule 4
      5. Rule 5
      6. Rule 6
      7. Rule 7
      8. Rule 8
    6. Literals
    7. Integers
    8. Boolean
    9. The byte data type
    10. Arrays
      1. Fixed arrays
      2. Dynamic arrays
      3. Special arrays
        1. The bytes array
        2. The String array
      4. Array properties
    11. Structure of an array
    12. Enumerations
    13. Address
    14. Mappings
    15. Summary
  9. Global Variables and Functions
    1. The var type variables
    2. Variables hoisting
    3. Variable scoping
    4. Type conversion
      1. Implicit conversion
      2. Explicit conversion
    5. Block and transaction global variables
      1. Transaction and message global variables
      2. Difference between tx.origin and msg.sender
    6. Cryptography global variables
    7. Address global variables
    8. Contract global variables
    9. Summary
  10. Expressions and Control Structures
    1. Solidity expressions
    2. The if decision control
    3. The while loop
    4. The for loop
    5. The do...while loop
    6. The break statement
    7. The continue statement
    8. The return statement
    9. Summary
  11. Writing Smart Contracts
    1. Smart contracts
    2. Writing a simple contract
    3. Creating contracts
      1. Using the new keyword
      2. Using address of a contract
    4. Constructors
    5. Contract composition
    6. Inheritance
      1. Single inheritance
      2. Multi-level inheritance
      3. Hierarchical inheritance
      4. Multiple inheritance
    7. Encapsulation
    8. Polymorphism
      1. Function polymorphism
      2. Contract polymorphism
    9. Method overriding
    10. Abstract contracts
    11. Interfaces
    12. Summary
  12. Functions, Modifiers, and Fallbacks
    1. Function input and output
    2. Modifiers
    3. The view, constant, and pure functions
    4. The address functions
      1. The send method
      2. The transfer method
      3. The call method
      4. The callcode method
      5. The delegatecall method
    5. The fallback function
    6. Summary
  13. Exceptions, Events, and Logging
    1. Error handling
      1. The require statement
      2. The assert statement
      3. The revert statement
    2. Events and logging
    3. Summary
  14. Truffle Basics and Unit Testing
    1. Application development life cycle management
    2. Truffle
    3. Development with Truffle
    4. Testing with Truffle
    5. Summary
  15. Debugging Contracts
    1. Debugging
      1. The Remix editor
      2. Using events
    2. Using a Block Explorer
    3. Summary
  16. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think