Chapter 9. Developing a browser-based blockchain node

 

This chapter covers

  • Creating a web client for a blockchain
  • Creating a small library for hash generation
  • Running the blockchain web app and debugging TypeScript in the browser

In chapter 8, we developed an app that would create a blockchain, and we provided a script for adding blocks to it. We launched that app from the command line, and it ran under the Node.js runtime.

In this chapter, we’ll modify the blockchain app so that it runs in the browser. We won’t use a web framework here, so it will have a pretty basic UI. We’ll use standard browser API methods, like document.getElementById() and addEventListener().

In this app, each block will store data about several transactions. They won’t be simple strings as in chapter 8 but will be implemented as TypeScript custom types. We’ll accumulate several transactions and then create the block to be inserted in the blockchain. Also, we created a small library that contains the code for mining blocks and generating the proper hash; this library can be used in a browser as well as in the Node.js environment.

This chapter’s app includes practical examples of the following TypeScript (and JavaScript) syntax elements covered in part 1 of this book:

  • Using private and readonly keywords
  • Using TypeScript interfaces and classes for declaring custom types
  • Cloning objects using the JavaScript spread operator
  • Using the enum keyword
  • Using async, await, and a Promise

9.1. Running the blockchain web app

 
 

9.2. The web client

 
 

9.3. Mining blocks

 
 
 
 

9.4. Using crypto APIs for hash generation

 
 
 
 

9.5. The standalone blockchain client

 
 

9.6. Debugging TypeScript in the browser

 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest