This repository implements simple blockchain using TypeScript. It is a rewrite of the original one created in Python from this article.
Run npm start -- -port <port-number>
to start the blockchain node.
Run npm run tsc:watch
to start TypeScript compiler and run npm run watch
to start node in watch mode.
Blockchain implements basic Proof of Work algorithm. Miners need to find a number that, when hashed with the previous block’s solution (proof), creates a hash with 4 leading 0s ('0000').
Blockchain class methods proofOfWork and validProof implements Proof of Work algorithm.
Consensus algorithm ensures that all nodes in decentralized network reflect the same blockchain. Rule of Consensus algorithm is that the longest valid chain is authoritative. It is achieved by sending the whole chain to each of the nodes.