Understanding What a Block Chain Block Is

Updated Version

There’s an updated version of this article here:

A block chain block contains the following:

  • Transaction Data
  • A cryptographic hash ( fingerprint / signature ) of it’s content
  • A nonce value ( A random number used for cryptographic computation )
  • The hash of the previous block
  • A time stamp of a recent verified transaction

Lets look at an example. We will use the NPM Packages CryptoJS and NanoID to generate the signature and nonce.

Here’s our block:

import { SHA256 } from "crypto-js";
import { nanoid } from "nanoid";
class Block {
constructor(
public index: number,
public timestamp: string,
public data: any,
public precedingHash: string,
public nonce?: string) {
this.nonce = this.nonce ? this.nonce : nanoid();
}
signature() {
return SHA256(
this.index +
this.precedingHash +
this.timestamp +
this.nonce +
JSON.stringify(this.data)).toString();
}
}

Lets create two blocks with the same data. They should have the same signature:

const transactionData = {sender: "Ole Ersoy",recipient: "Satoshi Nakamoto",quantity: 1};const block1 = new Block(0, "02/02/2021", transactionData, "0", "nonce");const block2 = new Block(0, "02/02/2021", transactionData, "0", "nonce");console.log(`Signature of Block 1: ${block1.signature()}`);console.log(`Signature of Block 2: ${block2.signature()}`);

So we see that a Block has a unique signature that is determined by what it contains. This makes it very difficult to tamper with a block.

Demo

--

--

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
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation