区块链技术以太_区块链和以太坊的技术入门

区块链技术以太

I attended a talk on Ethereum sometime back and was fascinated by the possibilities it provided and started exploring the ecosystem. It is a pretty nascent ecosystem that is catching up fast among the developer community. In this post I will explain the technology behind Ethereum so that we can get started with developing with Ethereum. This assumes you have technology background and basic understanding of blockchain so that we can discuss the Ethereum implementation.

有时我参加了有关以太坊的演讲,并对它提供的可能性着迷,并开始探索生态系统。 这是一个新兴的生态系统,正在开发者社区中Swift追赶。 在这篇文章中,我将解释以太坊背后的技术,以便我们可以开始使用以太坊进行开发。 假设您具有技术背景和对区块链的基本了解,以便我们可以讨论以太坊的实现。

第一件事 (First things first)

Blockchain provides a de-centralized, peer to peer network where digital assets can be transferred from one peer to another. The major problem we face in a de-centralized network is who will verify the validity of all the transactions taking place? The short answer is everyone.

区块链提供了一个去中心化的 点对点网络,其中数字资产可以从一个点转移到另一个点。 我们在去中心化网络中面临的主要问题是谁将验证所有正在进行的交易的有效性? 简短的答案是每个人。

Imagine a document with some information . Each person in the network keeps a copy of the same document. If there is an update in the document, it is propagated across the network and everyone updates their own copy of the document. Lets say a new person comes with different content in the document, then all the others can verify their copy and detect that the new person is lying and kick him out of the network. This is basically how a blockchain works.

想象一下包含一些信息的文档。 网络中的每个人都保留相同文档的副本。 如果文档中有更新,则该更新会通过网络传播,每个人都将更新自己的文档副本。 假设一个新人在文档中带有不同的内容,那么其他所有人都可以验证其副本并检测到该新人在撒谎并将其踢出网络。 基本上这就是区块链的工作方式。

First we need to understand few basic terms to get started.

首先,我们需要了解一些基本术语才能上手。

杂凑 (Hash)

We can use a cryptographic hash function(SHA256) to convert any string to its equivalent hash. The hash has two unique properties:

我们可以使用加密哈希函数(SHA256)将任何字符串转换为其等效的哈希。 哈希具有两个独特的属性:

  1. The hash produced has one to one mapping with the input string. The same input always produces the same unique hash and no other input can have the same hash.

    产生的哈希与输入字符串具有一对一的映射关系。 相同的输入始终会产生相同的唯一哈希,并且其他任何输入都不能具有相同的哈希。

  2. Even a small change in the input string will lead to a large change in the output hash and thus the input can be easily validated.

    即使输入字符串中的微小变化也将导致输出哈希值中的较大变化 ,因此可以轻松地验证输入。

交易 (Transaction)

The process by which assets are moved from one party to another in the network is known as Transaction. All transactions are recorded and permanently stored.Lets say A wants to transfer 5 Ether to B. Then this is a transaction in the network.

资产从网络中的一方转移到另一方的过程称为交易。 所有交易都被记录并永久存储。假设A想要将5个以太币转移到B。这是网络中的交易。

(Block)

Many transactions are combined together to form a block. Each block consists a unique hash which identifies it in the network. A block is chained to previous block using the hash of the previous block.

许多交易组合在一起形成一个块。 每个块均包含一个唯一的哈希 ,可在网络中对其进行标识。 使用前一个块的哈希将一个块链接到前一个块。

创世块 (Genesis Block)

The initial block or state of the blockchain that is agreed upon by all the nodes in the network.

网络中所有节点都同意的区块链的初始块或状态。

区块链 (Blockchain)

As the transactions are added many blocks are created and then they are chained together using their hashes into blockchain network.

随着交易的增加,创建了许多区块,然后使用其哈希将它们链接在一起,形成区块链网络。

工作证明 (Proof of work)

A proof of work is a piece of data which is difficult (costly, time-consuming) to produce but easy for others to verify and which satisfies certain requirements. When there is a transaction in the network, any node that tries to process the transaction should solve a cryptographic puzzle for it to be accepted to the block. This is known as proof of work. The work that is to be performed can be done only by trial and error and this has to be performed for any valid transaction in the network before it can become part of the blockchain.

工作量证明是难以生成(昂贵,耗时)但他人易于验证且满足某些要求的数据。 当网络中存在事务时,任何尝试处理该事务的节点都应解决密码难题,以使其能够被该块接受。 这被称为工作证明。 只能通过反复试验才能完成将要执行的工作,并且必须先对网络中的任何有效交易执行此工作,然后才能使其成为区块链的一部分。

矿业 (Mining)

The process of processing a transaction and adding it to the block by carrying out the proof of work is known as mining. The miners(nodes) get the rewards of the transaction once the transaction is accepted as part of the blockchain.

通过执行工作证明来处理交易并将其添加到区块中的过程称为挖掘。 一旦交易被接受为区块链的一部分,矿工(节点)将获得交易的奖励。

默克尔树 (Merkle Tree)

A Merkle tree is a tree in which every non-leaf node is labelled with the hash of the labels of its child nodes. We can verify that the data blocks received from other nodes are received undamaged and unaltered, and even to check that the other nodes do not lie and send fake blocks.

Merkle树是一棵树,其中每个非叶节点都用其子节点的标签的哈希标记。 我们可以验证从其他节点接收到的数据块是否完好无损,甚至可以检查其他节点没有说谎并发送假块。

加工 (Working)

We can now move on to basic working of a blockchain.

现在,我们可以继续进行区块链的基本工作。

  1. Each node starts with genesis block and builds its way up to the “current state” of the blockchain. When it receives a new block each node verifies its hash and thus validates if its a valid block or not and keeps building the chain.

    每个节点都从创世块开始,并逐步发展到区块链的“当前状态”。 当它收到一个新块时,每个节点都会验证其哈希值,从而验证其是否为有效块,并继续构建链。
  2. Once there is a transaction in the network, the miner mines it by generating the required proof of work. Then the miner adds it to his copy of the network and propagates the change to the nearby nodes.

    一旦网络中存在交易,矿工将通过生成所需的工作证明来进行挖掘。 然后,矿工将其添加到他的网络副本中,并将更改传播到附近的节点。

  3. All the nodes which receives it will validate the proof of work and then add it to their respective copies. If it is not valid, then the block is not added to the chain.

    收到它的所有节点都将验证工作量证明,然后将其添加到其各自的副本中。 如果无效,则不会将块添加到链中。
  4. When there is a conflict in the network , then the “longest chain rule” is applied to resolve it. Lets say two miners claim the same block and both have valid proof of work. Then the longest chain rule is applied which is whichever miner has the longest chain of blocks will be taken as the winner and that is added to the blockchain.

    当网络中存在冲突时,将应用“最长链规则”来解决它。 假设有两个矿工声称拥有相同的区块,并且都拥有有效的工作证明。 然后应用最长的链条规则,无论哪个区块链最长的矿工都将被视为获胜者,并将其添加到区块链中。

以太坊 (Ethereum)

Now that you have got a grasp of blockchain lets move ahead with Ethereum. Ethereum is a decentralized platform that allows us to write applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third party interference. It consists of Ethereum Virtual Machine(EVM) which provides the container in which all the smart contracts can be executed.

现在您已经掌握了区块链,让我们继续以太坊。 以太坊是一个去中心化的平台,它使我们能够编写完全按照编程方式运行的应用程序,而不会出现停机,审查,欺诈或第三方干扰的可能性。 它由以太坊虚拟机(EVM)组成,该虚拟机提供了可以在其中执行所有智能合约的容器。

智能合约 (Smart contracts)

Ethereum allows us to write applications on the blockchain and this applications are known as smart contracts. These smart contracts reside on the blockchain and they are immutable in nature, ie. the code cannot be deleted or modified in the blockchain once it is deployed. This can be written using Solidity or other languages, but the most preferred is solidity. It is a turing complete language.

以太坊允许我们在区块链上编写应用程序,这种应用程序被称为智能合约。 这些智能合约位于区块链上,并且本质上是不可变的 。 部署后,无法在区块链中删除或修改代码。 可以使用Solidity或其他语言编写,但最优选的是Solidity。 这是一种图灵完整的语言。

(Ether)

Ether is the cryptocurrency used in the Ethereum blockchain.

以太是以太坊区块链中使用的加密货币。

帐目 (Accounts)

In Ethereum, the state is made up of objects called “accounts”, with each account having a 20-byte address and state transitions being direct transfers of value and information between accounts. There are two types of accounts in Ethereum:

在以太坊中,状态由称为“帐户”的对象组成,每个帐户都有20字节的地址,状态转换是帐户之间价值和信息的直接转移。 以太坊有两种类型的账户:

  • Externally owned accounts : These accounts are owned by users, controlled by private keys. An externally owned account has no code, and one can send messages from an externally owned account by creating and signing a transaction.

    外部拥有的帐户:这些帐户由用户拥有,由私钥控制。 外部拥有的帐户没有代码,并且可以通过创建和签名交易来从外部拥有的帐户发送消息。

  • Contract accounts: These accounts are owned by contract code. In a contract account, every time the contract account receives a message its code activates, allowing it to read and write to internal storage and send other messages or create contracts in turn.

    合同帐户:这些帐户归合同代码所有。 在合同帐户中,合同帐户每次接收到一条消息时,其代码就会激活,从而使其可以读写内部存储并发送其他消息或依次创建合同。

加油站 (Gas)

As smart contracts are turing complete any infinity loop or other code can be written and the blockchain can be crashed. To prevent from such attacks Ethereum uses a concept called gas. Gas is nothing but some transaction cost which is paid to execute the transaction using Ether(basic currency in Ethereum chain). Each instruction requires some gas to be executed and the gas is sent along with any call that needs to modify the blockchain.

随着智能合约的完善,任何无限循环或其他代码都可以编写,并且区块链可能崩溃。 为了防止这种攻击,以太坊使用了一种称为gas的概念。 天然气不过是一些交易费用,使用以太币(以太坊链中的基本货币)执行交易需要支付一定的交易费用。 每条指令都需要执行一些指令,并且指令与需要修改区块链的任何调用一起发送。

DAPPS (DAPPS)

These are distributed apps that can be built using the smart contracts and providing an interface for the users(accounts). Different kinds of applications can be developed which will interact with smart contracts residing in the blockchain.

这些是可以使用智能合约构建并为用户(帐户)提供界面的分布式应用程序。 可以开发各种类型的应用程序,这些应用程序将与区块链中的智能合约进行交互。

使用以太坊的基本工作流程 (Basic Workflow using Ethereum)

We can discuss a basic workflow in Ethereum network for better understanding of how all these concepts work together in unison.

我们可以讨论以太坊网络中的基本工作流程,以更好地了解所有这些概念如何协同工作。

  1. We can write smart contracts and deploy it to Ethereum network. Once deployed these contracts cannot be changed.

    我们可以编写智能合约并将其部署到以太坊网络。 一旦部署,这些合同就无法更改。
  2. Any account or another smart contract in the network can execute these smart contracts functions through transactions.

    网络中的任何帐户或其他智能合约都可以通过交易执行这些智能合约功能。
  3. The smart contracts can be called and executed by sending transactions to the contract. These transactions cost gas and a certain gas should also be sent along with the transaction.

    可以通过将交易发送到合约来调用和执行智能合约。 这些交易成本气体和某些气体也应与交易一起发送。

  4. Sometimes we just need to know the state of some contract without modifying the blockchain. These are known as calls and they do not cost any gas.

    有时我们只需要了解某些合同的状态而无需修改区块链。 这些被称为通话,它们不花费任何汽油。

  5. We can build various Dapps by executing the smart contracts using transactions and calls , thus allowing the user to directly interact the smart contract in different ways.

    我们可以通过使用交易和调用执行智能合约来构建各种Dapp,从而允许用户以不同方式直接交互智能合约。

I believe this post provides basic understanding of the blockchain and Ethereum. In my next post I will provide a detailed guide to getting started with building Dapps using Ethereum.

我相信这篇文章提供了对区块链和以太坊的基本了解。 在我的下一篇文章中,我将提供有关使用以太坊构建Dapp的详细指南。

If you liked this story, feel free to reach out to me at https://kaizencoder.com/

如果您喜欢这个故事,请随时通过https://kaizencoder.com/与我联系。

翻译自: https://www.freecodecamp.org/news/technical-primer-to-blockchain-ethereum/

区块链技术以太

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值