Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Solidity Programming Essentials
Solidity Programming Essentials

Solidity Programming Essentials: A beginner's guide to build smart contracts for Ethereum and blockchain

eBook
$20.98 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Solidity Programming Essentials

Installing Ethereum and Solidity

In the previous chapter, we had an overview of all major concepts related to blockchains, particularly focusing on ones related to Ethereum and discussed the fundamentals related to working with blockchains in general. Ethereum-based blockchain solutions can be deployed to multiple networks. They can be deployed on public networks, test networks, or private networks. This chapter focuses on introducing and deploying Ethereum-based tools and utilities that are needed for building Ethereum-based solutions. There are plenty of tools in the Ethereum ecosystem and this chapter will focus on some of the most important and necessary tools. The tools will be deployed on Windows Server 2016 on Azure Cloud. However, they can be deployed on Linux, Mac, and any virtual machine or physical computer, as well. This will also be used as our development environment...

Ethereum networks

Ethereum is an open source platform for creating and deploying distributed applications.

Ethereum is backed up by a large number of computers (also known as nodes)—all interconnected and storing data in a distributed ledger. Distributed ledger here means that a copy of this ledger is available to each and every node on the network. It provides flexibility to its developers to deploy their solution to multiple types. Developers should choose an appropriate network based on their requirements and use cases. These different networks also help in deploying solutions and smart contracts on networks that do not actually cost any Ether or money. There are networks that are free of cost while there are ones that require its users to pay in terms of Ether or other currencies for its usage.

...

Geth

Implementation of Ethereum nodes and clients is available in multiple languages, including Go, C++, Python, JavaScript, Java, Ruby, and more. The functionality or usability of these clients are the same across languages, and developers should choose an implementation they are most comfortable with. This book uses the Go implementation known as Geth, which acts as an Ethereum client to connect to public and test networks. It is also used to create the mining and EVM (transaction nodes) for private networks. Geth is a command-line tool written in Go for creating a node and miners on a private chain. It can be installed on Windows, Linux, and Mac as well. Now, its time to install Geth.

Installing Geth on Windows

The first...

Creating a private network

After Geth is installed, it can be configured to run locally without connecting to any network on the internet. Every chain and network has a genesis block or the first block. This block does not have any parent and is the first block of the chain. A genesis.json file is required to create this first block. A sample genesis.json file is shown in the following code snippet:

{  
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x200",
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash&quot...

ganache-cli

There are following two distinct phases in the overall modification and writing of transactions to a ledger using Ethereum:

  • The first stage is about creating a transaction and putting the transaction in a transaction pool.
  • The second phase that happens periodically is to get all transactions from a transaction pool and mine them. Mining here means writing those transactions to the Ethereum database or ledger.

From this description, it would be a time-consuming process if the same process is used for development and testing purposes. To ease the process of development and test of solutions and smart contracts on Ethereum, ganache-cli was created. It was earlier known as TestRPC. ganache-cli by itself contains both the Ethereum transaction processing and mining functionality. Moreover, there is no waiting period for mining of transactions. The transactions are...

Solidity compiler

Solidity is one of the languages that is used to author smart contracts. Smart contracts will be dealt with in detail in the following chapters. The code written using Solidity is compiled using a Solidity compiler, which outputs byte code and other artifacts needed for deployment of smart contracts. Earlier, Solidity was part of the Geth installation; however, it has moved out of Geth and should be deployed using its own installation.

The Solidity compiler also known as solc can be installed using npm:

npm install -g solc

The preceding command line generates the following output:

The web3 JavaScript library

The web3 library is an open source JavaScript library that can be used to connect to Ethereum nodes from the same or a remote computer. It allows IPC as well as RPC to connect to Ethereum nodes. web3 is a client-side library and can be used alongside a web page and query and can submit transactions to Ethereum nodes. It can be installed using the node package manager as a node module like the Solidity compiler. At the time of writing, the latest version of web3 is broken and does not install appropriately because of the missing BigNumber.js file. However, previous stable versions can be used for connecting web applications to backend Ethereum nodes. Let's take a look at the following steps to install the web3 JavaScript library:

  1. The command used to install web3 is as follows:
npm install web3@0.19

The preceding command generates the following...

Mist wallet

Ethereum works with Ether cryptocurrency and a wallet is required to send and receive Ether. Mist is an implementation of the same. Mist is a wallet used to send and receive Ether. It helps in executing transactions on the Ethereum network. The network can be public or private. It allows users to create their accounts, send and receive Ether, and deploy and invoke contracts.

Mist can be downloaded from https://github.com/ethereum/mist/releases. Download an appropriate ZIP file (in this case it is Ethereum-Wallet-win64-0-9-2.zip since we are deploying on Windows 2016) and extract to a file location. Double-click on the Ethereum Wallet application from the extracted files as shown in the following screenshot:

This should start Mist. Mist is an intelligent wallet. If a private chain is running on a local machine then it can identify the same and connect to it. If there...

Ethereum networks


Ethereum is an open source platform for creating and deploying distributed applications.

Ethereum is backed up by a large number of computers (also known as nodes)—all interconnected and storing data in a distributed ledger. Distributed ledger here means that a copy of this ledger is available to each and every node on the network. It provides flexibility to its developers to deploy their solution to multiple types. Developers should choose an appropriate network based on their requirements and use cases. These different networks also help in deploying solutions and smart contracts on networks that do not actually cost any Ether or money. There are networks that are free of cost while there are ones that require its users to pay in terms of Ether or other currencies for its usage.

Main network

The main Ethereum network is a global public network that anybody can use. It can be accessed using an account and everybody is free to create an account and deploy their solutions and...

Geth


Implementation of Ethereum nodes and clients is available in multiple languages, including Go, C++, Python, JavaScript, Java, Ruby, and more. The functionality or usability of these clients are the same across languages, and developers should choose an implementation they are most comfortable with. This book uses the Go implementation known as Geth, which acts as an Ethereum client to connect to public and test networks. It is also used to create the mining and EVM (transaction nodes) for private networks. Geth is a command-line tool written in Go for creating a node and miners on a private chain. It can be installed on Windows, Linux, and Mac as well. Now, its time to install Geth.

Installing Geth on Windows

The first step in creating a private Ethereum network is to download and install Geth (go-ethereum) tool.

In this section, the steps to download and install Geth on Windows are as follows:

  1. Geth can be downloaded from the https://ethereum.github.io/go-ethereum/downloads/ page. It is...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • 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

Description

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.

Who is this book 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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 20, 2018
Length: 222 pages
Edition : 1st
Language : English
ISBN-13 : 9781788838375
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 20, 2018
Length: 222 pages
Edition : 1st
Language : English
ISBN-13 : 9781788838375
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 132.97
Mastering Blockchain
$54.99
Solidity Programming Essentials
$38.99
Ethereum Smart Contract Development
$38.99
Total $ 132.97 Stars icon

Table of Contents

11 Chapters
Introduction to Blockchain, Ethereum, and Smart Contracts Chevron down icon Chevron up icon
Installing Ethereum and Solidity Chevron down icon Chevron up icon
Introducing Solidity Chevron down icon Chevron up icon
Global Variables and Functions Chevron down icon Chevron up icon
Expressions and Control Structures Chevron down icon Chevron up icon
Writing Smart Contracts Chevron down icon Chevron up icon
Functions, Modifiers, and Fallbacks Chevron down icon Chevron up icon
Exceptions, Events, and Logging Chevron down icon Chevron up icon
Truffle Basics and Unit Testing Chevron down icon Chevron up icon
Debugging Contracts Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6
(10 Ratings)
5 star 40%
4 star 20%
3 star 10%
2 star 20%
1 star 10%
Filter icon Filter
Top Reviews

Filter reviews by




Murughan Palaniachari May 14, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Such an amazing book to start from nothing to become expert in Blockchain Ethereum and Solidity programming. I really like the examples for each topics explained in this book which gives confidence on how things works. This book has more than 100 examples which is really amazing. Thanks for capturing object oriented, contract oriented concepts in depth on Solidity programming language. This book covers both Public and Private Blockchain implementation. Concepts like Azure Ethereum Virtual Machine, Storage and Memory data locations, Cryptography, Ethereum Networks, Mist Wallet are explained very well and example for each of these concepts made me understand the concepts well.Also good coverage on tools and plugins like Truffle, Metamask, Remix, Azure EVM, Mist Wallet.Writing smart contracts made easy with this book.I recommend people to learn from this book for beginner to expert level.
Amazon Verified review Amazon
悩めるサラリーマン Jan 06, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
趣味レベルでプログラミングをしており、2年ほどpythonとJavaScriptの経験があります。これまで2冊Ethereumに関する本を読みましたが、Solidityのコーディングという意味では、この本が最も分かりやすく構成も優れています。翻訳本も出ているようですが、翻訳されたプログラミングの本には良い印象を持っていません。この本は平易な英語で書かれており、かつ理解しにくいテーマについては深く掘り下げて読者が理解できるよう丁寧な説明を心がけています。お勧めです。
Amazon Verified review Amazon
aman Jun 27, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have read multiple books on Blockchain and some of them touch the topic on Solidity fleetingly by providing a small chapter on it. This is the first book I have come across that is completely dedicated to Solidity as a programming language. I liked the way the book is organized and progresses ensuring that readers get accustomed to almost every important concept on Solidity. There are a ton of examples in this books which shows how you can utilize it in many different scenarios. Very hands-on approach for learning this important programming language on Blockchain and Ethereum. Just loving it!
Amazon Verified review Amazon
JONATHAN Apr 17, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Like it said it does have a lot of the basics very good as a reference source of information but more information is needed to get your computer set up for solidity programming lots of dependencies you have to install a lot of things that are not covered but still this is more the basics. It makes learning easier as I can go back and reference the code examples
Amazon Verified review Amazon
Pruthvi Kumar Dec 09, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
For Solidity enthusiasts, this should be the bible. There isn't much available anyways apart from standard doc's. Ritesh has done a good job in explaining the topics. Book is well organized. Its important for readers to have OOPS background to swim through chapters with ease.Reason for 4 stars: I would have liked a chapter or two on security, vulnerability and industry best practices for Solidity.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.