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:
- 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) {
});
- 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 => {
});
});
- Inside of this forEach loop, let's do the same things that we've done...