Create your own pocket sized blockchain in JavaScript – CoinGeek

Create your own pocket sized blockchain in JavaScript – CoinGeek

In this article, we’ll explore how we can create a nano sized blockchain with JavaScript. In fact, we’ll be using less than 30 lines of code to achieve this.

But why?

There are two good reasons to follow along. If you know any code, but don’t know anything about blockchain, this will help you get a top-level understanding of what the blockchain comprises of, or, more specifically, the structure of blocks in Bitcoin. The second reason for following along is, if you know a few things about blockchain but only beginning your coding journey, this will be a fun little project to build on.

Without further ado—let’s get cracking!

First is first, we will need to use a cryptography library in order to be able to do one of the most common functions done in Bitcoin and blockchain technology: Hashing. The crypto library we’ll be using is the very popular crypto-js library. Indeed, it is overkill to load the entire library when I can just use the SHA256 component, but let’s keep it simple and short. So from a terminal window (command prompt), type in npm install crypto-js

Our first line will require we load this library object into a variable. We will use the name CryptoJS.

Javascript