区块链c端应用小程序

by Sean Han

通过肖恩·韩

区块链如何真正起作用? 我建立了一个应用程序向您展示。 (How does blockchain really work? I built an app to show you.)

According to Wikipedia, a blockchain is:

根据维基百科,一个区块链是:

A distributed database that is used to maintain a continuously growing list of records, called blocks.

一种分布式数据库,用于维护不断增长的记录列表(称为块)

That sounds nice, but how does it work?

听起来不错,但如何运作?

To illustrate a blockchain, we will use an open source command-line interface called Blockchain CLI.

为了说明区块链,我们将使用一个名为Blockchain CLI的开源命令行界面。

I also built a browser-based version of this here.

我还在这里构建了基于浏览器的版本 。

安装命令行界面版本 (Installing the Command-Line Interface version)

If you haven’t already, install Node.js.

如果尚未安装Node.js。

Then run the following in your terminal:

然后在终端中运行以下命令:

# Clone this repository
$ git clone https://github.com/seanseany/blockchain-cli# Go into the repository
$ cd blockchain-cli# Install dependencies
$ npm install# Run the app
$ npm start

You should see ? Welcome to Blockchain CLI!and a blockchain → prompt ready to take commands.

你应该看到? Welcome to Blockchain CLI!a ? Welcome to Blockchain CLI!a和ab lockchain →提示准备好接受命令。

块是什么样的? (What does a block look like?)

To see your current blockchain, enter blockchain or bc into the command prompt. You should see a block like the image below.

要查看您当前的区块链,请在命令提示符下输入blockchainbc 。 您应该看到如下图所示的块。

  • Index (Block #): Which block is it? (Genesis block has index 0)

    索引(块号):它是哪个块? (创世记块的索引为0)

  • Hash: Is the block valid?

    哈希:该区块有效吗?

  • Previous Hash: Is the previous block valid?

    上一个哈希:上一个区块有效吗?

  • Timestamp: When was the block added?

    时间戳记:什么时候添加了该区块?

  • Data: What information is stored on the block?

    数据:块上存储了什么信息?

  • Nonce: How many iterations did we go through before we found a valid block?

    Nonce:在找到有效块之前,我们经历了几次迭代?

创世块 (Genesis Block)

Every blockchain will start with the? Genesis Block. As you will see later, each block on the blockchain is dependent on the previous block. So, the Genesis block is needed to mine our first block.

每个区块链都将以? Genesis Block. ? Genesis Block. 如您将在后面看到的,区块链上的每个块都依赖于前一个块。 因此,需要Genesis区块来挖掘我们的第一个区块。

开采新区块时会发生什么? (What happens when a new block is mined?)

Let’s mine our first block. Enter mine freeCodeCamp♥︎ into the prompt.

让我们开采我们的第一个街区。 在提示中输入mine freeCodeCamp♥︎

The blockchain looks at the latest block on the blockchain for the index and previous hash. In this case Genesis block is the latest block.

区块链将查看区块链上的最新区块以获取索引和先前的哈希值。 在这种情况下,Genesis块是最新的块。

  • Index: o+1 = 1

    索引: o + 1 = 1

  • Previous Hash: 0000018035a828da0…

    上一个哈希: 0000018035a828da0…

  • Timestamp: When the block is added

    时间戳:添加块时

  • Data: freeCodeCamp❤

    数据: freeCodeCamp❤

  • Hash: ??

    哈希:

  • Nonce: ??

    Nonce: ??

哈希是如何计算的? (How is the hash calculated?)

A hash value is a numeric value of a fixed length that uniquely identifies data.

哈希值是唯一标识数据的固定长度的数字

The hash is calculated by taking the index, previous block hash, timestamp, block data, and nonce as input.

通过将索引,先前的块哈希,时间戳,块数据和随机数作为输入来计算哈希。

CryptoJS.SHA256(index + previousHash + timestamp + data + nonce)

The SHA256 algorithm will calculate a unique hash, given those inputs. The same inputs will always return the same hash.

给定这些输入,SHA256算法将计算唯一的哈希。 相同的输入将始终返回相同的哈希。

您是否注意到区块哈希中的四个前导0? (Did you notice the four leading 0’s in the block hash?)

The four leading 0’s is a minimum requirement for a valid hash. The number of leading 0’s required is called difficulty.

有效散列的最低要求是四个前导0。 所需的前导0的数字称为难度

function isValidHashDifficulty(hash, difficulty) {for (var i = 0, b = hash.length; i < b; i ++) {if (hash[i] !== '0') {break;}}return i >= difficulty;
}

This is also known as the Proof-of-Work system.

这也称为工作量证明系统 。

什么是随机数? (What’s a nonce?)

A nonce is a number used to find a valid hash.

随机数是用于查找有效哈希的数字。

let nonce = 0;
let hash;
let input;while(!isValidHashDifficulty(hash)) {     nonce = nonce + 1;input = index + previousHash + timestamp + data + nonce;hash = CryptoJS.SHA256(input)
}

The nonce iterates until the hash is valid. In our case, a valid hash has at least four leading 0’s. The process of finding a nonce that corresponds to a valid hash is mining.

随机数迭代直到哈希有效为止。 在我们的情况下,有效哈希至少具有四个前导0。 查找与有效哈希对应的随机数的过程是采矿

As the difficulty increases, the number of possible valid hashes decreases. With less possible valid hashes, it takes more processing power to find a valid hash.

随着难度的增加 ,有效哈希的数量会减少 有效哈希越少,查找有效哈希就需要更多处理能力。

为什么这么重要? (Why does this matter?)

It matters because it keeps the blockchain immutable.

这很重要,因为它使区块链保持不变。

If we have the following blockchain A → B → C, and someone wants to change data on Block A. This is what happens:

如果我们有以下区块链A→B→C,并且有人想要更改区块A上的数据,则会发生这种情况:

  1. Data changes on Block A.数据在A块上更改。
  2. Block A’s hash changes because data is used to calculate the hash.块A的哈希值发生变化,因为数据用于计算哈希值。
  3. Block A becomes invalid because its hash no longer has four leading 0’s.块A无效,因为其哈希不再具有四个前导0。
  4. Block B’s hash changes because Block A’s hash was used to calculate Block B’s hash.块B的哈希值发生变化,因为使用了块A的哈希值来计算块B的哈希值。
  5. Block B becomes invalid because its hash no longer has four leading 0's.块B无效,因为其哈希不再具有四个前导0。
  6. Block C’s hash changes because Block B’s hash was used to calculate Block C’s hash.块C的哈希值发生变化,因为使用了块B的哈希值来计算块C的哈希值。
  7. Block C becomes invalid because its hash no longer has four leading 0's.块C无效,因为其哈希不再具有四个前导0。

The only way to mutate a block would be to mine the block again, and all the blocks after. Since new blocks are always being added, it’s nearly impossible to mutate the blockchain.

变异方块的唯一方法是再次挖掘该方块,然后再挖掘所有方块。 由于总是会添加新的块,因此几乎不可能对区块链进行变异。

I hope this tutorial was helpful for you!

希望本教程对您有所帮助!

If you would like to checkout a web version of the demo, head on over to http://blockchaindemo.io

如果您想查看该演示的网络版本,请转到http://blockchaindemo.io

翻译自: https://www.freecodecamp.org/news/how-does-blockchain-really-work-i-built-an-app-to-show-you-6b70cd4caf7d/

区块链c端应用小程序

区块链c端应用小程序_区块链如何真正起作用? 我建立了一个应用程序向您展示。...相关推荐

  1. 比特币程序_比特币如何运作? 我建立了一个应用程序向您展示。

    比特币程序 by Sean Han 通过肖恩·韩 比特币如何运作? 我建立了一个应用程序向您展示. (How does bitcoin work? I built an app to show you ...

  2. 区块链需要用到mysql吗_区块链和传统数据库有什么区别?

    都说区块链就是一种数据库,那区块链和传统数据库到底有什么区别呢? 传统数据库拥有与其记录相关的授的客户机可以更改放在统一服务器上的部分.通过演进"ace副本",无论客户端在什么时候 ...

  3. 我的第一个安卓应用程序_今天,我启动了我的第一个移动应用程序。 这是我学到的...

    我的第一个安卓应用程序 by Harshita Arora 通过Harshita Arora 今天,我启动了我的第一个移动应用程序. 这是我学到的 (Today I launched my first ...

  4. 外链引入css有哪些方式_外链怎么发才会快速收录?

    外链似乎还依然是大部分行业获取关键词排名的主要方法,现在早已经过来外链是王道的时代.但是对于处于关键词排名前期的新站,外链的作用依然很大.如何才能让我们发布的外链快速被收录然后被计入关键词排名呢?有如 ...

  5. 创建自己第一个安卓程序_从一天创建和发布我的第一个应用程序中学到的东西...

    创建自己第一个安卓程序 by Sarvasv Kulpati 由Sarvasv Kulpati 从一天创建和发布我的第一个应用程序中学到的东西 (What I learned from creatin ...

  6. iis 反向代理 应用程序_我如何反向工程字节并创建自己的字节Web应用程序

    iis 反向代理 应用程序 Byte, a new app from Vine cofounder Dom Hofmann, has been released on Android and iOS. ...

  7. linux应用程序的编写实验原理,操作系统实验 1.在linux下编写一个应用程序 联合开发网 - pudn.com...

    操作系统实验 所属分类:Linux/Unix编程 开发工具:C/C++ 文件大小:1KB 下载次数:3 上传日期:2019-05-01 20:34:21 上 传 者:烟雨南风起 说明:  1.在lin ...

  8. 区块链钱包技术上怎么实现_区块链钱包的技术原理

    区块链钱包实现的技术原理用一句话表示就是:钱包助记词生成了种子,种子发芽结果,果实就是私钥,私钥推导出了公钥,公钥数据的节选部分成了钱包地址.同时钱包提供了Key Store,他也是私钥加密后的文件为 ...

  9. 区块链带来的价值包括哪些_爱链社区干货:区块链技术为冷链物流带来的了那些价值?...

    冷链物流泛指在一些特殊需求商品(如部分医药和食品)的生产和消费环节中,为了保证这些商品在生产.贮藏运输.销售,到消费前的各个环节始终处于规定的低温环境下,以保证其品质的一项系统工程. 为了保证实现这项 ...

最新文章

  1. 系统管理工具top、glances、dstat比较
  2. python语音翻译-python利用有道翻译实现“语言翻译器”的功能
  3. Flash cs5 初试
  4. Mysql的分库分表(基于shardingsphere)
  5. 从SAP客户主数据里直接创建商机(Opportunity)
  6. 【人脸对齐-Landmarks】人脸关键点检测方法及评测汇总
  7. Hadoop RPC框架
  8. yjv是电缆还是电线_2019最新电缆载流量对照表,不用每次都百度了!
  9. Oracle基础学习(四) 游标
  10. 常用代码大全(新手入门必备)
  11. 哈工大中文分词系统ltp4j使用总结
  12. 二叉树之自底向上递归
  13. 计算机行业的最新技术,计算机行业发展空间巨大 三大必然趋势引领发展
  14. 服务器引导损坏怎么处理,硬盘主引导记录(MBR)损坏,一个命令轻松解决问题...
  15. 利用计算机解决鸡兔同笼问题,用计算机解决“鸡兔同笼”
  16. BZOJ5336:[TJOI2018]游园会——题解
  17. colab运行在本地
  18. @vuecomposition-apidistvue-composition-api.mjs in .node_modulesvue-demilibindex.mjs 报错
  19. 什么是802.11ac和802.11ac Wave2
  20. 09.python常用数据类型—字典

热门文章

  1. u-charts 曲线图中间有部分没数据,导致点和点无法连成线的问题解决
  2. liunx学习笔记(一:常用命令)
  3. tf.nn.relu
  4. Android应用工程文件组成
  5. manage.py命令
  6. Emoji表情图标在iOS与PHP之间通信及MySQL存储
  7. finecms设置伪静态后分享到微信不能访问怎么处理
  8. 练习 MongoDB 操作 —— 备份篇(三)
  9. ClassFlow推出全新课堂活动轨迹功能
  10. 烂泥:ubuntu下配置msmtp+mutt发送邮件