Building the /consensus endpoint

Now, let's build the /consensus endpoint, which will use the chainIsValid method that we built in the previous section. Carry out the following steps to build the endpoint:  

  1. Let's go to networkNode.js file and, after the /register-node-bulk endpoint, define the /consensus endpoint as follows:
app.get('/consensus', function(req, res) { });
  1. Next, inside of the /consensus endpoint, let's make a request to every other node inside of the blockchain network to get their copies of the blockchain and compare them to the copy of the blockchain that's hosted on the current node that we're currently on:
app.get('/consensus', function(req, res) {        bitcoin.networkNodes.forEach(networkNodeUrl => {        });         });
  1. Inside of ...

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.