This article covers the implementation of Merkle Tree and Patricia Trie in Node.js and also covers some theoretical aspects for both these data structures.

Photo by Jeremy Bishop on Unsplash

Introduction

  1. About Merkel Trees and Patricia Tries
  2. Algorithm
  3. Implementation in Node.js

Merkel Trees

To simply put, Merkel Trees are essentially a tree data structure in which data is stored in the leaf nodes and non leaf nodes store hashes of data with each non-leaf node being the combined hash value of…


In this article, we will understand the working of practical byzantine fault tolerance in Blockchain systems, the math behind this algorithm, its significance, write its pseudo code, and then implement it in node.js

Source: Unsplash

Declaimer: This article is NOT a tutorial on blockchain. It is assumed that readers have sufficient knowledge about blockchain/bitcoin.

Before talking about PBFT lets understand some terminologies that revolve around it.

Fault tolerance and Fault tolerant systems


Ever since its invention, blockchain has been claimed by its evangelists as a disruptive technology that will change the way the world works. But after 10 years hence, in spite of its unparalleled benefits, blockchain has failed to mainstream adoption. One of the primary reasons for the failure of blockchain frameworks such as Ethereum and Bitcoin, that has hindered the mass adoption of these technologies, is that the conventional centralized systems have more to offer than decentralized blockchain systems.

Source: Unsplash

In response to the low adoption of blockchain, researcher and developers identified a trilemma comprising of decentralization, speed, and security which…


Accounts, Stake and Validators

In the previous post, we create a wallet, signed transactions and broadcasted them to the network. In this post we will add a few extra features into our app. We will implement an account model, stake model, and validator list.

Accounts


Leader, blocks and ICO

In the previous post, we create accounts, stake model and validators. In this post, we will create an ICO and a static leader for our application. We also add a threshold to our blocks which will limit its size and also tell us when we should determine the next leader.

Transaction Threshold

Create a constant TRANSACTION_THRESHOLD which will be used as a size of a block and add it to the config.js file

// config.js
const TRANSACTION_THRESHOLD = 5;
const TRANSACTION_FEE = 1;


This article presents an easy implementation of Proof of Stake consensus algorithm in node.js

In the previous post, we created a basic p2p-server and an API to interact with our blockchain. In this part, we’ll further extend our project and we will implement a wallet.

The Wallet

Digital signatures allow users to verify the miner which created the block and the transaction. …


This article presents an easy implementation of Proof of Stake consensus algorithm in node.js

In the previous post, we coded a basic blockchain. In this part, we will implement the functionality to validate a chain and add multiple contributors.

To add the support of multiple contributors, we need to add some form of validation. Each node in the network might have a different chain at some point in time. To achieve a common state we need to validate the new chains that we receive for other nodes. In bitcoin, the longest chain rule is used. In which, the chain which…


This article presents an easy implementation of Proof of Stake consensus algorithm in node.js

Source bitcoin wiki

In the previous post, we went through an introduction to the proof of stake, how it works and also talked about the design and architecture of the code that we will be implementing.

In this post, we’ll be starting coding.

Prerequisites:

  1. Node.js and NPM
  2. Text Editor ( with a dark theme 😛)
  3. Postman or any other app to interact with HTTP APIs.

That’s it.

Let’s Code:

mkdir poschain
cd poschain


This article presents an easy implementation of Proof of Stake consensus algorithm in node.js

Source: Bitcoin Wiki

Proof of Stake

In order to add new blocks to the blockchain, an algorithm is required to decide which node gets the ability to add a block to the blockchain. Hence, this is the primary goal of any consensus algorithm.

Working


Cryptocurrency is just one use case of blockchain technology; in fact, its applications are limitless. As such, let’s take a look at 5 industries that blockchain will overhaul in the coming years.

Blockchain technology was invented in 2008 by Satoshi Nakamoto and can be simply understood as a ledger of records that is immutable, decentralized and secure.

A blockchain has 4 major components:

  1. A distributed network of computers or servers
  2. An algorithm responsible for database state management
  3. Transactions represent a change in the state of the network
  4. A ledger of records or a data structure to store transactions

Each computer…

Kashish Khullar

You landed at the right place

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store