+1 (208) 254-6996 essayswallet@gmail.com

Contrasting local and public test blockchains Contrasting local and public test blockchains.

In chapter 4, the author discusses different options for testing blockchain applications. For our course, we have chosen to use Ganache, a local test blockchain. Explore some of the advantages and disadvantages of using local and public blockchains to test apps and contrast the two options.  

CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 59

Chapter 4 Examining the Ethereum Ecosystem and Development Lifecycle

The Ethereum blockchain implementation provides a rich environment for developing decentralized blockchain applications. These decentralized applications, or dApps, are unique in that the code and data are stored in the blockchain. Each node executes the code in the same way and guarantees that the results are the same.

The capability to deploy application code and data across an entire network ensures that the shared ledger remains the same for all nodes and that changes are allowed only in specific circumstances. The blockchain doesn’t need an external authority to determine whether data is valid — the rules that govern the blockchain itself determine whether new data is valid and can be added to the blockchain.


» Examining the Ethereum blockchain structure

» Understanding smart contracts and Solidity

» Paying for blockchain access

» Surveying Ethereum development tools

» Exploring the Ethereum application development lifecycle

60 PART 2 Setting Up Your Ethereum Development Environment

In this chapter, you discover the components of an Ethereum dApp. You find out how code modifies the blockchain, and how to pay for the ability to add data. And finally, you learn about the Ethereum dApp development process, what tools you need to develop dApps, and how the pieces fit together.

Exploring the Ethereum Blockchain Block Structure

Ethereum dApps primarily populate blocks, add them to the blockchain, and query existing blocks. That sounds pretty simple, right? However, lots and lots of details are hidden in those simple goals. Before you can start to build blocks and add them to the blockchain, you need to know a little bit more about the contents of an Ethereum block and how the chain is built.

I describe only basic block and chain details. The authoritative reference for Ethereum internals is the Ethereum yellow paper, at https://ethereum.github. io/yellowpaper/paper.pdf. You can also find a pretty good third-party detailed discussion of Ethereum block structure internals at https://ethereum.stack exchange.com/questions/268/ethereum-block-architecture.

A block is a data structure that contains two main sections: a header and a body. Transactions are added to the body and then submitted to the blockchain network. Miners take the blocks and try to solve a mathematical puzzle to win a prize. Miners are just nodes, or pools of nodes, with enough computational power to calculate block hashes many times to solve the puzzle. In Ethereum, the mining process uses the submitted block header and an arbitrary number called a nonce (number used once). The miner picks a value for the nonce, which is part of the block header, and calculates a Keccak-256 hash on the block header. The result has to match an agreed-upon pattern, which gets more difficult over time as miners gets faster at mining blocks. If the first mining result doesn’t match the pattern, the miner picks another nonce and calculates a hash on the new block header. This process continues until a miner finds a nonce that results in a hash that matches the pattern.

The miner that finds the solution broadcasts that solution to the rest of the network. That miner collects a reward, in ETH, for doing the hard work to validate the block. Because many miners work on blocks at the same time, it’s common for several miners to solve the hash puzzle at almost the same time. In other block- chains, these blocks are discarded as orphans. In Ethereum, these blocks are called uncles. An uncle block is any successfully mined block that arrives after that block

CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 61

has already been accepted. Ethereum accepts uncle blocks and even provides a reward to the miner, but the reward is smaller than the one for the accepted block.

Ethereum rewards miners of uncle blocks to reduce mining centralization and to increase the security of the blockchain. Uncle rewards provide an incentive for smaller miners to participate. Otherwise, mining would be profitable for only large pools, which could eventually take over all mining. Encouraging more min- ers to participate also increases security by increasing the overall work carried out on the entire blockchain.

The header of a block contains data that describes the block, and the body contains all the transactions stored in a block. Figure  4-1 shows the contents of an Ethereum block header.

Each Ethereum block header contains information that defines and describes the block, and records its place in the blockchain. The block header contains these fields:

» Previous hash: The hash value of the previous block’s header, where the previous block is the last block on the blockchain to which the current block gets added.

FIGURE 4-1: Ethereum block


62 PART 2 Setting Up Your Ethereum Development Environment

Ethereum uses the Keccak-256 algorithm to produce all hash values. The National Institute of Standards and Technology (NIST) Secure Hashing Algorithm 3 (SHA3) is a subset of the Keccak algorithm. Ethereum was introduced before the SHA-3 standard was finalized, and Keccak-256 does not follow the SHA-3 official standard.

» Nonce: A number selected that causes the hash value of the current block’s header to adhere to a specific pattern. If you change this value (or any header value), the hash of the header changes. You learn more about how Ethereum uses the nonce value shortly.

» Timestamp: The date and time the current block was created. » Uncles hash: The hash value of the current block’s list of uncle blocks, which

are stale blocks that were successfully mined but arrived just after the accepted block was added to the blockchain.

» Beneficiary: The miner’s account that receives the reward for mining the block.

» Logs bloom: Logging information stored in a Bloom filter (a data structure useful for quickly finding out if some element is a member of a set).

» Difficulty: The difficulty level used in mining the block. » Extra data: As the name implies, any extra data used to describe the block. » Block number: The unique number for the block (assigned sequentially). » Gas limit: The limit of gas for the block. (You learn about gas later in this


» Gas used: The amount of gas used by transactions in the block. » Mix hash: A hash value that is combined with the nonce value to show that

the mined nonce meets difficulty requirements. This hash increases the difficulty for attackers to modify any block.

» State root: The hash value of the root node of the block’s state trie. A trie is a data structure that efficiently stores data for quick retrieval. The state trie is used to express information about the state of transactions in the block without having to look at the transactions.

» Transaction root: The hash value of the root node of the trie that stores all transactions for the block.

» Receipt root: The hash of the root node of the trie that stores all transaction receipts for the block.

CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 63

The body of an Ethereum block is just a list of transactions. Unlike other block- chain implementations, the number of transactions — and as a result the size of blocks — isn’t fixed. Every transaction has a processing cost associated with it, and each block has a limited budget. Ethereum blocks can contain lots of inexpen- sive transactions or just a few expensive ones or anything in between. Ethereum designed a lot of flexibility into what blocks can contain. Figure 4-2 shows the content of an Ethereum transaction.

Ethereum transactions contain the following fields:

» Nonce: Each Ethereum account keeps track of the number of transactions it executes. This field is the latest transaction, based on the account’s counter. The network uses the transaction nonce to ensure that transactions for that particular account are executed in the proper order.

» Signature: The digital signature of the account owner, proving the identity of the account requesting this transaction.

» Gas price: Unit price that the account is willing to pay to execute this transaction.

» Gas limit: Maximum total amount you are willing to pay to execute this transaction.

» To: The address that is the recipient of this transaction. For transfers, the address is the account that will receive the transfer. For calling functions, the address is the address of the smart contract.

FIGURE 4-2: Contents of

an Ethereum transaction.

64 PART 2 Setting Up Your Ethereum Development Environment

» Value: The total amount of ether you want to send to the recipient. » Data: The actual data submitted as the transaction body. Each type of

transaction may have different data based on its functionality. For calling functions, the data may contain parameters.

As users submit transaction requests to nodes, the nodes create transactions and submit them to the transaction pool. Miners then pick transactions from the pool and build new blocks. After an Ethereum mining node constructs a block, it starts the mining process. The first miner to complete the mining process adds the block to the blockchain and broadcasts the new block to the rest of the network.

You can look at the public Ethereum blockchain at any time by going to Etherscan at https://etherscan.io/. Etherscan lets you see blockchain statistics as well as block and transaction details.

Describing Smart Contracts When you exchange items of value, generally rules govern how the transaction takes place. In many cases, the rules are simple. For example, you me $1.89, and I give you a soft drink. Each party can see and validate the other party’s contribu- tion to the transaction. If you try to give me Monopoly money, you won’t get your soft drink. Even though this transaction seems simple, there’s more to it than meets the eye. In most cases, if a soft drink costs $1.89, you’ll have to tender more than that for it. You’ll have to pay taxes as well. So there’s another participant in the transaction: the government. Instead of keeping all the money, I have to send some of it to the government for taxes.

Moving even simple transactions like the soft drink example into the digital world takes some careful thought. You can’t just send money to people and trust that they’ll do their part. You need some way to enforce rules and compliance to make sure that all parties are treated fairly.

Smart contracts help you enforce rules when you exchange anything of value in Ethereum. The simplest way to describe smart contracts is that they are programs that execute when certain transactions occur. For example, if you create a soft- drink-purchase smart contract, that software code will run every time someone buys a soft drink. The smart contract code is stored in the blockchain, so all nodes have a copy of it. Also, it doesn’t matter where the software runs: All nodes are guaranteed to run it the same and get the same results as every other node.

CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 65

Ethereum smart contracts are Turing complete, which means they can compute anything that is computable with enough resources. Turing completeness is important because Ethereum smart contracts aren’t limited in the types of actions they can carry out. They can carry out any complex algorithms you can design.

The soft-drink smart contract starts with the buyer. Here’s how the exchange might happen:

» The buyer creates a transaction that sends money to the seller in exchange for the soft drink.

» The buyer sends the seller’s address as input to the smart contract’s address. » The smart contract runs to carry out the transaction. It verifies that you have

enough money in your account to pay for the soft drink.

» The smart contract verifies that the seller has the soft drink you want in stock. » The smart contract deducts funds from the buyer, sends the funds to the

seller, and tells the seller to send the soft drink to the buyer. In the same step, the smart contract sends the required tax to the tax authority account and sends the remaining amount to the seller’s account.

The process may seem tedious, but it is straightforward and makes sure each transaction occurs in the same way. This example is too simple for real-life exchanges, and I left out some important details. For starters, we assume that the seller will send the soft drink to the buyer. Real-life exchanges require an extra layer of protection for both sides. Smart contracts use escrow accounts (see Chapter 3) all the time to hold a buyer’s money until the seller delivers the goods or services.

Smart contracts provide the governance and predictability of Ethereum. Without them, Ethereum would just be a cool distributed storage technique. But with them, Ethereum is a stable decentralized platform that supports interactions and exchanges between untrusting users, including extremely complex transactions. It is easy to see the steps necessary to buy a soft drink. Other transactions, such as real estate transactions, are far more complex, have many dependencies and requirements, and generally involve several people and organizations. Ethereum smart contracts can help developers create software that eliminates middlemen, streamlines complex processes, and reduces the overall cost and time required to complete even the most complex exchanges.

66 PART 2 Setting Up Your Ethereum Development Environment

Introducing Solidity, the Language of Smart Contracts

Smart contracts are software programs. With enough resources, smart contracts can do anything any other software can do. You can write Ethereum smart con- tracts in several languages:

» Mutan: An older smart contract language that was deprecated in 2015. » LLL: A Lisp-like language, obviously developed to look like the language Lisp.

Although LLL is still supported, it’s not used for many current smart contract projects.

» Serpent: A language that looks like the Python language. As of September 2017, Serpent is not recommended for current development.

» Bamboo: A relatively new language that focuses on making blockchain state transitions explicit and avoiding code reentrant issues.

» Viper: Another relatively new language that focuses on security and simplicity. » Solidity: Currently the most popular smart contract development language.

Solidity looks like the JavaScript language and provides a full-featured language for developing general-purpose smart contracts.

Solidity is the most popular language for smart contracts, and the one you’re most likely to encounter. For that reason, I chose to focus on Solidity in this book.

If you’re comfortable with JavaScript, picking up Solidity will be a little easier. If you don’t know much JavaScript, that’s okay. You’re going to learn the basics of Solidity from the ground floor. In fact, I start with a program that may look famil- iar: the ubiquitous “Hello world” program.

You’ll see this code again in Chapter 7, where you dig deeper into each part of this simple program. For now, take a look at this very simple smart contract code:

pragma solidity ^0.4.25;

contract helloWorld {

function printHelloWorld () public constant returns (string) {

return ‘Hello world!’;



CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 67

That’s what a Solidity smart contract looks like! After the heading, you define your contract, and then any functions that make up the inner workings of the program. After you write and test a smart contract, you can deploy it to a blockchain (more about this in Chapter 7), and then execute it. When you get everything right, your smart contract will show you the iconic “Hello world!” message.

As you learn more about Solidity, you’ll see that it does look a lot like JavaScript but also feels a bit like C++ and Python. The developers of Solidity based the lan- guage on all three languages. It supports inheritance, libraries, and user-defined types that can be quite complex. It is also a statically typed language, which means you have to provide explicit datatypes for the variables you create and use.

Above all, Solidity is a smart contract development language. Even though it looks like other languages, it includes primitives and an orientation designed to interact with the Ethereum blockchain. In Chapters 8 and 9 you learn a lot more about how to write to and read from the Ethereum blockchain by using Solidity.

Working with the Ethereum Virtual Machine

You write smart contract code in Solidity, but it won’t run in its source form. Almost all programs written in any language have to be translated into a runnable format. Some languages, such as C++, are compiled languages. When you write a C++ program, you have to use a compiler to compile the program into an execut- able that an operating system can run. Other languages, such as Python, are inter- preted. You run a program that provides a runtime environment, which interprets your code and executes the commands.

Other languages, such as Java and Solidity, exist in-between compiled and inter- preted languages. You compile the programs you write in both of these languages, but you compile your source code to opcode, also called bytecode. Opcode is an optimized sequence of operations that your language’s runtime environment can understand. The runtime environment is often referred to as the language’s vir- tual machine. In Java, programs run in the Java virtual machine (JVM). All Solidity smart contracts run in the Ethereum virtual machine (EVM).

The EVM is present on all nodes. When you install Ethereum, you get the EVM, and it runs whenever you run Ethereum. That means any time a smart contract runs, it runs on all EVMs across the Ethereum network. Ethereum ensures that smart contracts run the same way on all nodes and get the same results. That’s how the blockchain remains consistent across all nodes.

68 PART 2 Setting Up Your Ethereum Development Environment

The EVM uses a stack-based architecture, and has its own area in memory for the code it runs and the data it stores in addition to each smart contract’s local stor- age. Although the EVM is a Turing complete virtual machine, its execution is lim- ited by the amount of gas allowed by each smart contract run. That limitation avoids using excessive computing power for nodes across the Ethereum network (or bankrupting an account with a programming error or malicious code that tries to run forever.).

As you can see, running every smart contract on every node in the Ethereum net- work is a lot of work. Every additional instruction in a smart contract causes thou- sands of nodes to do more work. To reduce the computation waste on so many machines, Ethereum includes incentives for using computation resources conser- vatively and sets upper limits on just how much work a smart contract can carry out. In the next section you learn about how Ethereum sets these limits.

Fueling Your Code with Gas A couple of the fields in the block header include the word gas. Those fields refer to the cryptocurrency cost of accessing the blockchain and executing code. Because Ethereum storage and processing is distributed across many nodes, individuals and organizations need an incentive to commit their computing resources to blockchain operation. Gas is that incentive.

Gas refers to the fee that transaction initiators pay to process their operations. Ethereum users use ether to pay miners. To keep costs manageable, each transac- tion has a maximum amount of gas you’re willing to pay. If you set this limit too low, many miners may pass up your transaction and you may have to wait to get your transaction into a block. After your transaction is selected by a miner, you have to pay a small amount of gas for every computational step required to com- plete the transaction. The good news is that you don’t have to pay the maximum each time you start a transaction and you get a refund for any gas that isn’t used in the transaction.

Gas serves several purposes in the Ethereum ecosystem. First, it encourages developers to create efficient smart contracts, which require less computational resources than sloppy or unoptimized smart contracts. Any savings of computa- tional resources are magnified by the thousands of nodes on the Ethereum net- work. Being conservative lowers costs all around.

Second, gas limits make it harder for malicious users to write code to consume available network resources. Denial of service (DoS) attacks on Ethereum net- works could tie up all nodes if unrestrained smart contracts were allowed to run. Gas allows upper limits to be established that stop DoS attacks in their tracks.

CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 69

And finally, charging gas for accessing data stored on the blockchain discourages blockchain growth because it makes developers think through the justification for putting data on the blockchain. This approach also encourages developers to be creative when determining how to store context data. Although in many cases it would be easier to store data in a block, gas cost often leads to other designs that leverage local storage.

Two main variables are used to calculate the total cost of a transaction:

» Gas used: The total amount of gas that a transaction uses. Each computation in a smart contract has an associated computation price.

» Gas price: The price, in Ether, of one unit of gas used in the transaction.

The formula for calculating the cost of gas for a transaction is

Total gas cost = Gas used * Gas price

If you’re interested in calculating your own gas usage, every Ethereum operation and its associated cost (in gas) is listed in the spreadsheet at http://ethereum. stackexchange.com/q/52/42.

Gas price is expressed in wei units. Wei is a denomination of ether cryptocurrency. One ether (ETH) equals 1e18 wei (that’s 1,000,000,000,000,000,000 wei). The current gas price fluctuates, but at the time of this writing, it’s somewhere around 2 Gwei (2,000,000,000 wei).

Ethereum gives both miners and transaction requesters substantial flexibility. If you request a transaction, you get to set a maximum gas price and total amount of gas you’re willing to pay. That gives you the ability to limit your cost. Of course, if your limits are too low, your transaction may never make it to the blockchain. From the miner perspective, you can cherry-pick the transactions you want to put into blocks. When cash flow is high, you can choose only the best paying transac- tions. On the other hand, when things are slower, you have the option to take lower paying transactions. Regardless, Ethereum lets you choose.

Surveying Tools for Developing, Testing, and Deploying Ethereum Apps

You use different tools for every phase of the process of developing and deploying Ethereum dApps. Many tools are available; this section covers a few of the more popular ones.

70 PART 2 Setting Up Your Ethereum Development Environment

You need multiple tools to address the requirements of the multiple levels involved in developing Ethereum dApps: source code development, testing, compiling, and deploying your smart contract code. In this section, I briefly describe some of the more popular development tools in each of the following categories:

» Ethereum blockchain client: This software runs the Ethereum blockchain and EVM, making a computer a blockchain node.

» Development and testing blockchain: This tool sets up a local, or non-live, blockchain to use before deploying code to the live blockchain.

» Compiler and testing framework: A compiler translates source code into bytecode for the EVM, and testing tools help to identify and fix bugs.

» Source code editor and integrated development environment (IDE): These tools include editors and suites of tools designed to help developers write code.

Ethereum blockchain client The Ethereum blockchain client establishes an Ethereum node, downloads part, or all, of an Ethereum blockchain, and launches the EVM. Ethereum client software makes a computer or device an Ethereum node in the blockchain network.

Ethereum clients nodes can be full nodes or light nodes. Full nodes store the entire Ethereum blockchain, which at the time of this writing is 182.5 GB. You can go to https://bitinfocharts.com/ to see the current Ethereum blockchain size, along with lots of other stats for popular blockchains. That’s a lot of storage to dedicate just to keeping a copy of a blockchain. An alternative to full nodes is to connect to the blockchain network as a light node. Light nodes store only a portion of the blockchain. Either way, you need to install Ethereum client software to connect to the network.

Remember the root hash fields in the Ethereum block header layout shown earlier in the chapter? Light nodes download and store block headers but don’t fetch all of the block contents. That reduces the blockchain storage requirement to a point that small devices, even Raspberry Pi, can become light nodes. The light node fetches block contents only when to user needs it to complete some task, such as checking a balance or submitting a new transaction.

All Ethereum clients support the Ethereum standard and implement the EVM. The main difference between clients is the programming language in which each one

CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 71

is written. Because all clients provide the same core functionality, the choice is largely based on your language preference. Table  4-1 lists several Ethereum blockchain clients.

Development and testing blockchain One of the strongest features of blockchain technology is that the blockchain is immutable. Although that’s great for integrity, it makes developing smart con- tract code more difficult. Software rarely works correctly the first time its written. The development process is made up of multiple snapshots of software as it matures to become the final product.

Putting your code on the live Ethereum public blockchain is the last step in the development process. Before you’re ready to do that, you need a local or non-live blockchain environment to use while developing and testing. That way, you put only the final, bug-free (you hope) version of your code on the live blockchain.

You don’t have to use separate tools to create a private blockchain. You can set one up yourself and configure your Ethereum client to use it instead of the live Ethe- reum network. If you want to build your own private blockchain from scratch, check out the resource at souptacular.gitbooks.io/ethereum-tutorials-and- tips-by-hudson/content/private-chain.html.

Tools in this category provide a development and testing blockchain that you can use while you add features to your code. Table 4-2 lists the four main Ethereum development and testing blockchains.

TABLE 4-1 Ethereum Clients Name Language Where to Get It

Cpp-ethereum C++ http://ethdocs.org/en/latest/ethereum-clients/ cpp-ethereum

Ethereumjs-lib JavaScript http://ethdocs.org/en/latest/ethereum-clients/ ethereumjs-lib

Geth (go-ethereum) Go htpps://ethereum.github.io/go-ethereum

Parity Rust https://www.parity.io/

Pyethapp Python http://ethdocs.org/en/latest/ethereum-clients/pyethapp

72 PART 2 Setting Up Your Ethereum Development Environment

Compiler and testing framework The EVM runs bytecode, so you’ll need a compiler to translate your source code into bytecode. Tools in this category also provide the functionality for monitoring how your smart contracts execute and identifying bugs. Table 4-3 lists several Ethereum compilers and testing frameworks.

Source code editor/IDE You can use any text editor to write smart contract sources code, but several editor environments are designed to help developers write and manage code. These tools help you to develop code efficiently. Table 4-4 lists several source code editors and IDEs that help you develop Ethereum smart contracts in Solidity.

TABLE 4-3 Ethereum Compilers and Testing Frameworks Name Description Where to Get It

Truffle Popular suite of tools to manage smart contract development, testing, and deployment


Solidity compiler (solc)

Solidity software includes a command-line compiler that can be called from IDEs


Solidity compile (solcjs)

Solidity compiler written in JavaScript github.com/ethereum/solc-js

Remix Web-based suite of Ethereum development tools that includes a Solidity compiler


Populus Web-based IDE for smart contract development github.com/ethereum/populus

Embark Framework for developing dApps for multiple blockchains

github.com/embark-framework/ embark

TABLE 4-2 Ethereum Development and Testing Blockchains Name Description Where to Get It

Ganache Most popular tool with developers for easily creating a private network


Truffle A suite of development tools that includes its own private network


Cliquebait Uses docker instances to simulate a real blockchain network


Local Ethereum Network

Easy-to-use scripts to set up private block- chain networks

github.com/ConsenSys/local_ ethereum_network

CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 73

Describing the Ethereum Development Lifecycle

Smart contract development generally follows the same process as the traditional software development lifecycle, but with a few nuances. The basic steps in the software development lifecycle are as follows:

» Planning: This phase includes gathering specifications and designing the solution.

» Coding/development: After planning is complete, developers start writing code to implement the planned solution.

» Testing: Unit testing should occur throughout the coding phase, but after all coding is complete, the entire software product undergoes testing to ensure that all the pieces work together as designed. If testers find flaws, you have to go back at least to the coding phase, and perhaps even to the planning phase, to make changes to fix the flaws.

» Deployment: After fixing any remaining flaws, the properly functioning software is released to the production environment. This phase also includes maintenance activities, which monitor the software and respond to newly identified flaws or requests for enhancements.

Although the main phases of the software development lifecycle are the same for smart contract development, the design of blockchain technology raises a few

TABLE 4-4 Source Code Editors/IDEs Name Language Where to Get It

Atom Popular IDE with Solidity extensions atom.io

Visual Studio Code Microsoft’s IDE with Solidity extensions marketplace.visualstudio.com/items? itemName=JuanBlanco.solidity

Vim Solidity Solidity extensions for Vim (a vi-like editor) github.com/tomlion/vim-solidity

Remix Web-based IDE popular with new Solidity developers


EthFiddle Web-based IDE focused on simplicity ethfiddle.com

Superblocks Lab Web-based IDE with many built-in blockchain integration features


Pragma Simple web-based IDE that offers auto-generated code segments


74 PART 2 Setting Up Your Ethereum Development Environment

issues. First, remember that the blockchain data is immutable. Also, smart contracts are deployed to blocks in the blockchain. After you deploy a smart con- tract, it can never change. That’s good if you want it to stick around forever, but it can be bad if you find out later that you deployed a smart contract with a bug. Figure 4-3 shows the smart contract software development life cycle.

Testing is more important when dealing with blockchain technology because updating smart contracts is awkward and can be difficult. Each new smart con- tract deployment gets a new address, so you have to ensure that all references to the old smart contract are updated to refer to the new smart contract. Also, you have to be careful about how the updated smart contract handles data. If the changes you made in the smart contract change how it handles data, you’ll have to figure out how to deal with the data already in the blockchain. Another issue is that until you deploy a smart contract, you’ll be testing it on a local, or private, blockchain. Your test environment may not reflect how the real blockchain operates.

These are just a few issues you’ll encounter when developing for a blockchain. Pay attention to the quality of your testing activities. Thorough testing takes time, but it can save a lot more.

Introducing Smart Contract Development Tools

In the following chapters, you learn how to set up a development environment and develop smart contracts by using the Solidity language. As you learned in this chapter, multiple tools are available for each stage of development. Instead of

FIGURE 4-3: Smart contract

software development


CHAPTER 4 Examining the Ethereum Ecosystem and Development Lifecycle 75

covering all the tools, I chose one from each category so you can focus on learning Solidity. You can use a different tool if you want — all of the ones listed are good choices.

Here is what you will use:

» Ethereum blockchain client: You’ll use Geth, which is easy to install. Many tutorials use Geth as their client.

» Development and testing blockchain: Ganache-cli is the chosen develop- ment and testing blockchain. Ganache-cli makes it easy to set up new blockchains to test your smart contracts.

» Compiler and testing framework: I chose the Truffle suite, which provides an effective and easy-to-use collection of tools for compiling and testing your new smart contracts.

» Source code editor/integrated development environment (IDE): This choice was the hardest. From so many good options, I chose the Atom IDE. For your development, try a few alternative editors/IDEs as well to see which one is your favorite.

In the next chapter, you learn how to download, install, and configure these tools. Then you’ll be ready to learn how to develop your own smart contracts.