Reader small image

You're reading from  Learn Blockchain Programming with JavaScript

Product typeBook
Published inNov 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781789618822
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Eric Traub
Eric Traub
author image
Eric Traub

Eric Traub currently works as a software engineer in New York City. He has extensive experience working as a teacher and instructing people in a variety of different subjects. He changed his career from teaching to software engineering because of the excitement it brings to him and the passion that he has for it. He is now lucky enough to have the opportunity to combine both of these passions - software engineering and teaching!
Read more about Eric Traub

Right arrow

Preface

With the help of this book, you'll get to build your own blockchain prototype and a decentralized network by using the JavaScript programming language. Building your own blockchain will help you understand various concepts related to blockchains, such as how blockchain technology works under the hood, how decentralized blockchain networks function, and how to code the blockchain and decentralized network using JavaScript. Also, you will get to learn why blockchain is such a secure and valuable technology.

The blockchain that you'll build throughout this book will have functionalities that are similar to those you would find on a real-life blockchain, such as Bitcoin or Ethereum. Your blockchain will have functionalities such as the ability to mine new blocks, create new and immutable transactions, and perform a proof of work to secure the blockchain. In addition to these, your blockchain will consist of many other important features. You'll get to explore those as you read further through the chapters.

When you have completed this book, you will have a thorough understanding of how blockchain technology actually works and why this technology is so secure and valuable. You will also have a deep understanding of how decentralized blockchain networks function and why decentralization is such an important feature for securing the blockchain.

Who this book is for

Learn Blockchain Programming with JavaScript is for JavaScript developers who wish to learn about blockchain programming or build their own blockchain using JavaScript frameworks.

What this book covers

Chapter 1, Setting Up the Project, covers what a blockchain actually is and enables readers to understand how it functions. Then, you'll get to learn how to set up a project in order to create your very own blockchain.

Chapter 2, Building a Blockchain, covers how to add various functionalities to your blockchain. You will implement the functionalities in the blockchain, creating some amazing methods such as createNewBlock, creatNewTransaction, and getLastBlock. Once these methods are added to the blockchain, you will test them to verify that they are working perfectly. Also, you'll get to learn about the hashing method, that is, SHA256 hashing, and then implement a method to generate a hash for your block data. Also, you'll get to explore what a proof of work is, how it benefits the blockchain, and how to implement it.

Chapter 3, Accessing the Blockchain through an API, explains how to set up Express.js in your project, as well as how to use it to build the API/server. Then, you will build various server endpoints for your blockchain and test these endpoints to verify whether or not they are working properly.

Chapter 4, Creating a Decentralized Blockchain Network, covers how to set up a decentralized network for your blockchain. In this chapter, you will get to learn a lot of new concepts related to how to set up various nodes and interconnect them to form a network. You'll also define various endpoints, such as /register-and-broadcast-node, /register-node, and /register-nodes-bulk. These endpoints will assist you in implementing the decentralized blockchain network.

Chapter 5, Synchronizing the Network, explains how to synchronize the entire decentralized blockchain network so as to have the same transaction data and blocks on all the nodes in the blockchain. You'll implement network synchronization by refactoring the endpoints to broadcast the data to all the nodes present in the network.

Chapter 6, Consensus Algorithm, explains how to build your own consensus algorithm, which implements the longest chain rule. Through implementing this algorithm, you will have built a blockchain that is similar to a real-life blockchain.

Chapter 7, Block Explorer, explains how to build an amazing user interface to explore the blockchain that you have built over the course of the book.

Chapter 8, In Conclusion..., provides a quick summary of everything you will have learned throughout the course of this book. You will also explore what more you can do to improve the blockchain that you have developed.

To get the most out of this book

A basic knowledge of JavaScript is recommended. You will also be required to install Node.js on your system.

The code and implementation of examples in this book were executed on macOS. However, if you want to implement all of these using a Windows PC, you will have to install the necessary requirements for it.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learn-Blockchain-Programming-with-JavaScript. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

Blockchain.prototype.createNewBlock = function () { 

}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

Blockchain.prototype.createNewBlock = function (nonce, previousBlockHash, hash) { 

}

Any command-line input or output is written as follows:

cd dev
touch blockchain.js test.js

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Go to More Tools, and then select the Developer Tools option."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learn Blockchain Programming with JavaScript
Published in: Nov 2018Publisher: PacktISBN-13: 9781789618822
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Eric Traub

Eric Traub currently works as a software engineer in New York City. He has extensive experience working as a teacher and instructing people in a variety of different subjects. He changed his career from teaching to software engineering because of the excitement it brings to him and the passion that he has for it. He is now lucky enough to have the opportunity to combine both of these passions - software engineering and teaching!
Read more about Eric Traub