Skip to content

Instantly share code, notes, and snippets.

@alexpanasUCLA
Last active September 9, 2021 14:52
Show Gist options
  • Save alexpanasUCLA/e0a2833ec5917847b304c86b8bfed12a to your computer and use it in GitHub Desktop.
Save alexpanasUCLA/e0a2833ec5917847b304c86b8bfed12a to your computer and use it in GitHub Desktop.
Block Class
const SHA256 = require('crypto-js/sha256');
class Block {
constructor(data){
this.hash = "",
this.height = 0,
this.body = data,
this.time = 0,
this.previousBlockHash = ""
}
static genesisBlock() {
let genesisBlock = new this("First block in the chain - Genesis block");
genesisBlock.hash = SHA256(JSON.stringify(genesisBlock)).toString();
return genesisBlock;
}
}
module.exports = Block;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment