Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apurva-modi/blockchain-in-js
Basic Blockchain Coded in JavaScript !!
https://github.com/apurva-modi/blockchain-in-js
Last synced: 8 days ago
JSON representation
Basic Blockchain Coded in JavaScript !!
- Host: GitHub
- URL: https://github.com/apurva-modi/blockchain-in-js
- Owner: apurva-modi
- Created: 2019-02-05T05:17:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T12:10:57.000Z (about 2 years ago)
- Last Synced: 2023-07-24T00:25:18.593Z (over 1 year ago)
- Language: JavaScript
- Size: 129 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Blockchain-in-JS
Basic Blockchain Coded in JavaScript!!## How to run.
1. Download Node.
2. Install all the dependencies as mentioned in the the package,json using npm.
3. Clone the Project and do npm start with the project working Directory.
4. Go to localhost:3000/blockchain to see the blockchain initially it contains genisis block.
5. Use Postman to POST new Transaction to a Block at this URL http://localhost:3000/transaction in JSON.
6. Go to localhost:3000/mine to mine the tranctions and to create new block to the blockchain and to earn modicoins.### blockchain.js contains the following.
1. It has a Constructor Function Blockchain() which initially consist of a genisis block.
2. It also has Different Prototype Function which are put to add property over the Blockchain which includes :
- createNewBlock - it returns a new indexed Block with the encrypted transactoin data with current hash, previous hash, timestamp and nonce.
- getLastBlock - it returns the last created Block.
- createNewTransaction - it responsible for adding a new transactional data over a block with amount of transaction and address of Merchant and Customer.
- hashBlock - it returns the hash of the current block by encrypting the current transaction data with the previous block and the nonce using SHA256.
- proofOfWork - it returns nonce with four 0's with every hash in the blockchain hence maintains the validation of the blockchain.### api.js contains the following.
This file contains 3 Events.
1. get blockhain - this event when triggered list the current state of the blockchain initially it only list the genisis block.
2. post transaction - this event is sresponsible to push the transaction data to theh blockcahin pending transaction array.
3. get mine - this event mines all the pending transaction in the block and if there are not transaction in the block then it mines the previous block itself and for every mine a new block is added to the blockchaain and the minner is rewarded for the same by 12.5 modicoin (this blockchain's cryptocurrency).