Summary

All blockchains have a consensus algorithm, and in this chapter, we built our own consensus algorithm that implements the longest chain rule. We started by building the chainIsValid method. In this method, we simply iterated through every single block inside of the blockchain, and compared hashes on every block to make sure that they are correct. Then we moved on to test the method. In addition to this, we built the /consensus endpoint with the help of the chainIsValid method.   

In the next chapter, we're going to build a block explorer that we'll be able to access on the browser. This block explorer will allow us to interact with the blockchain through a user interface.

Get Learn Blockchain Programming with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.