Giter VIP home page Giter VIP logo

basic-blockchain's Introduction

Basic Blockchain

A very basic blockchain written in JavaScript

An online blockchain demo.

The concept

A blockchain is a data structure like linked lists with a growing set of nodes or blocks. In a blockchain, each node is called a "block" and each block has an index, timestamp, hash of itself, hash of the previous block and some data.

The hash of each block gives it a unique identity like a fingerprint. A block's hash is generated only once when the block is created and it is generated using the values of all the other attributes of the block. Therefore, if any of the values are changed, the hash will no more be valid and hence the entire block will be invalidated. The calculation of the hash must be reproducable for verification purposes, i.e. a hash function for a given set of values must produce the same hash.

To actually link the blocks together to make a blockchain that cannot be tampered with, each block stores the hash of the previous block. Thus, if the hash of a single block changes, the chain will be broken and given that the last known valid block is now de-linked from the origin, the entire chain will be invalidated.

Mining

A cryptocurrency blockchain implementation has a concept of mining, whereby the hash of a block needs to fulfill certain criteria, e.g. the hash must start with 4 zeros or the hash must be a valid natural number under a certain value. To enable searching for a hash that meets this criteria, an additional flexible parameter called a nonce is added. A simple implementation might use a number as a nonce so that mining is simply looping over all possible numbers to find a fitting hash.

Moreover, a crypocurrency implementation also has the flexibility of choosing which transactions to group into a single block thereby enabling more options for mining.

Distributed verification

A cryptocurrency blockchain implementation also has it's entire blockchain replicated over many different peers. Not all peers have the full chain, as it is enough to keep only a recent portion of the chain for verification purposes. Most importantly, whoever has the longest chain is determined to have the correct copy of the blockchain!

Note that in a network like Bitcoin, the computational complexity of mining a block steadly increases so that it takes 10 minutes to mine a block. This computational complexity is known as difficulty and it could be as simple as increasing the amount of leading zeros that a hash needs to require to fulfill the mining criteria.

Rewards

In a cryptocurrency implementation, each block in a blockchain essentially stores a list of transactions. However, in order for someone to spend money, they need to initially get it. In the bitcoin world, this is known as a coinbase transaction.

Moreover, in order to make it lucrative for miners to spend the effort in mining blocks, each successfully mined block results in some reward for the miner.

basic-blockchain's People

Contributors

wheresvic avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.