更新时间:2021-06-10 18:41:08
coverpage
Title Page
About Packt
Why subscribe?
Packt.com
Contributors
About the author
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Setting up the Project
What is a blockchain?
What you will learn...
Environment setup
Project source code
Summary
Building a Blockchain
Before we get building...
An explanation of the JavaScript constructor function
Explanation of the prototype object
Blockchain constructor function
Building the createNewBlock method
Testing the createNewBlock method
Testing the Blockchain constructor function
Building the getLastBlock method
Creating the createNewTransaction method
Testing the createNewTransaction method
Adding a pending transaction to our blockchain
Hashing the data
Understanding the SHA256 hashing function
The hashBlock method
Testing the hashBlock method
What is a Proof of Work?
Creating the proofOfWork method
Testing the proofOfWork method
Creating a genesis block
Testing the genesis block
Accessing the Blockchain through an API
Setting up Express.js
Installing Express.js
Using Express.js
Building the API foundation
Installing Postman and body-parser
Installing Postman
Building the /blockchain endpoint
Testing the /blockchain endpoint
Building the /transaction endpoint
Testing the /transaction endpoint
Building the /mine endpoint
Testing the endpoints
/mine endpoint testing
Testing the / blockchain endpoint
Creating a Decentralized Blockchain Network
Creating multiple nodes
Running multiple instances of networkNode.js
Testing the multiple nodes
Adding the currentNodeUrl
New endpoints outline
Defining the /register-and-broadcast-node endpoint
Creating the /register-node endpoint
The difference between register-and-broadcast-node and register-node endpoint
Defining the /register-nodes-bulk endpoint
Understanding how all of the endpoints work together
Building the /register-and-broadcast-node endpoint
Continuing to work on the /register-and-broadcast-node endpoint
A quick recap of how the register-and-broadcast-node endpoint functions
Building the /register-node endpoint
Testing the /register-node endpoint
Installing the request library
Endpoint testing
Building the /register-nodes-bulk endpoint
Testing the /register-nodes-bulk endpoint
Testing all of the network endpoints
Synchronizing the Network
Understanding the need to synchronize the network
Refactoring the createNewTransaction method and the /transaction endpoint
Modifications to the createNewTransaction method
Building the addTransactionToPendingTransactions method
Building the /transaction/broadcast endpoint
Refactoring the /transaction endpoint
Testing the transaction endpoints
Recapping how to create the network
Updating the mining information
The updated mining process
Refactoring the /mine endpoint
Building the /receive-new-block endpoint
Testing the new and updated /mine endpoints