Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Solidity Programming Essentials
Solidity Programming Essentials

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

eBook
NZ$31.99 NZ$45.99
Paperback
NZ$56.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788831383
Category :
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

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 NZ$7 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 NZ$7 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total NZ$ 194.97
Ethereum Smart Contract Development
NZ$56.99
Solidity Programming Essentials
NZ$56.99
Mastering Blockchain
NZ$80.99
Total NZ$ 194.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.