200 lines of code to achieve a simple block chain __ block chain

Source: Internet
Author: User
Tags hash


Java| block chain development and communication group: 613121183

Interested can also add ha, provided a lot of block chain information, there will be information to share

The basic concept of a block chain is simple: a distributed database that stores an ever-growing list,list containing many sequential records. In general, however, when we talk about block chains, we also talk about the problem of using block chains, which can easily be confused. This is the case for a block-chain project like the popular Bitcoin and the Etheric square. The term "block chain" is often closely linked to concepts like trading, smart contracts, and cryptographic currencies.

This makes it much more difficult to understand the block chain, especially if you want to understand the source code. I will use the 200 line JS implementation of the super simple block chain to help you understand it, I gave this code named Naivechain. Block Structure

The first logical step is to determine the block structure. To ensure that things are as simple as possible, we only select the most necessary parts: index (subscript), timestamp (timestamp), data (data), hash (hash value), and previous hash (pre-hashing).

This block must be able to find the hash value of the previous block in order to ensure the integrity of the entire chain.

1 2 3 4 5 6 7 8 9 Class Block {constructor (index, Previoushash, timestamp, data, hash) {this. index = index; this. Previoushash = Previoushash.          ToString (); this.          timestamp = timestamp; this.          data = data; this. hash = hash.      ToString (); } }

Block Hash

In order to save the full data, you must hash the block. SHA-256 will encrypt the contents of the block, recording this value should have nothing to do with "digging", because there is no need to solve the problem of work proof.

1 2 3 var Calculatehash = (Index, Previoushash,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.