Book Image

Ethereum Smart Contract Development

By : Mayukh Mukhopadhyay
Book Image

Ethereum Smart Contract Development

By: Mayukh Mukhopadhyay

Overview of this book

Ethereum is a public, blockchain-based distributed computing platform featuring smart contract functionality. This book is your one-stop guide to blockchain and Ethereum smart contract development. We start by introducing you to the basics of blockchain. You'll learn about hash functions, Merkle trees, forking, mining, and much more. Then you'll learn about Ethereum and smart contracts, and we'll cover Ethereum virtual machine (EVM) in detail. Next, you'll get acquainted with DApps and DAOs and see how they work. We'll also delve into the mechanisms of advanced smart contracts, taking a practical approach. You'll also learn how to develop your own cryptocurrency from scratch in order to understand the business behind ICO. Further on, you'll get to know the key concepts of the Solidity programming language, enabling you to build decentralized blockchain-based applications. We'll also look at enterprise use cases, where you'll build a decentralized microblogging site. At the end of this book, we discuss blockchain-as-a-service, the dark web marketplace, and various advanced topics so you can get well versed with the blockchain principles and ecosystem.
Table of Contents (18 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

Coding a loop


Loops are very helpful when we need to repeat the execution of a piece of code a certain number of times. Rather than copying and pasting the same lines of code, making the code block longer, we use this programming construct to add brevity to our code. Loops can be finite or infinite in nature. For the infinite loop, we generally provide a break statement to come out of it.

The smart contract in Figure 3.16 is using a finite loop to calculate the summation of a finite number of integers:

Figure 3.16: Loop inside a Solidity smart contract

The output on remix IDE is shown in Figure 3.17. As discussed earlier, keep a watch on the amount of ethers that is getting decreased in the Account tab for each call of the myFirstLoop function:

Figure 3.17: Execution of myFirstLoop inside a smart contract

The best way to check the inner working of a loop in runtime is to go to the Launch debugger tab and manually push the horizontal scroll bar from left to right, as shown in Figure 3.18. Try...