BlockChain Implementation in Javascript Language along with the implementation of OOPs Concepts. A Decentralised network and Secure system to demonstrate the Working of blockchain.
The Structure of the blockchain is : -
class BlockChain { constructor() { this.chain = []; this.pendingTransactions = []; this.currentNodeUrl = currentNodeUrl; this.networkNodes = [ ... //List of all the nodes in the network...]; this.createNewBlock(100, '0', '0'); //Genesis Block } createNewBlock(nonce, previousBlockHash, hash) { const newBlock = { index: this.chain.length + 1, timestamp: Date.now(), transactions: this.pendingTransactions, nonce: nonce, hash: hash, previousBlockHash: previousBlockHash }; this.pendingTransactions = []; this.chain.push(newBlock); return newBlock; } //Other Functions(Features) }
The features that are added to the blockchain class:-
A proof of work algorithm to secure the network.
The proof-of-work is a mechanism for reaching global consensus on the valid blockchain: since all nodes have a copy of the blockchain, each node must agree on the conditions that prove how much effort a node has spent on verifying transactions.
To make the calculation difficult, every identification code must start with 0000 (four zeros). To do this we have to add a new field called NONCE.
proofOfWork(previousBlockHash, currentBlockData) { let nonce = 0; let hash = this.hashBlock(previousBlockHash, currentBlockData, nonce); while (hash.substring(0, 4) !== '0000') { nonce++; hash = this.hashBlock(previousBlockHash, currentBlockData, nonce); } return nonce; }
Hashing algorithms to secure the data within the blockchain.
The ability to mine (create) new blocks that contain data.
The ability to create transactions and store them in blocks.
An API/server that will be used to interact with the blockchain from the internet.
It will be hosted on a decentralized blockchain network.
A consensus algorithms to verify that the network nodes have valid data and are synchronized.
A broadcasting system to keep the data in the blockchain network synchronized.
I have experience with React, Nodejs, and Python while building my projects and during Internships.