The relationship between block chain and intelligent contract

Source: Internet
Author: User

Although Bitcoin (Bitcoin) and Ether Square (ethereum) are two words that are often mentioned together, there is a big difference between bitcoin and the etheric square. The only thing they have in common is that the ether is also a cryptographic asset running on a block chain.

Unlike Bitcoin, which is only a cryptographic currency, there are many other features in the etheric square. It is these characteristics that make the etheric square a centralized supercomputer.

Before we understand the etheric square, we have to understand how the block chain works. If you already know the block chain, or read the ultimate guide to understanding the block chain, you can go directly to the next section. What is a block chain.

to put it simply, a block chain is a database . It is a growing database that stores specific types of data and has some unique attributes: Once the data is stored in the database, it can never be modified or deleted. Every record on a block chain is permanent. This database is not maintained by a single individual or organization, but is maintained by tens of thousands of people, each of whom has a copy of the database.

To understand why several people can hold a copy and be able to sync with others, let's assume that there are now 10 people in the network, each with an empty folder and a blank sheet of paper. Whenever a person on the web does something, such as a transfer, they have to tell the other person in the network.

Everyone will record it on paper until it fills up the piece of paper. At this time, everyone must solve a mathematical problem to encapsulate this paper. By solving mathematical puzzles, the paper is guaranteed to have the same content in everyone's hands and cannot be modified. Who is the first to solve the problem, who will get a certain number of cryptographic money reward. More content is visible: The ultimate guide to understand blockchain.

Once encapsulated, the page is added to the folder, and a new page is taken, and the process continues to repeat.

As time went on, the pages (that is, chunks, blocks) that contained important records (that is, the transaction, transaction) were continually added to the folder (chain), eventually forming a database (block chain). what the block chain stores.

block chains can be used to store various types of data , and the data it stores gives the value of the block chain. The Bitcoin block chain stores financial transactions, so it looks like a dollar or pound currency. In addition to the functionality hosted by the dollar, Bitcoin does not have any additional functionality. However, the ether square is different.

The ether is not just a currency like a dollar, pound sterling or Bitcoin. The goal of the etheric Square is not only to become a currency, but to become something in the following image:

The etheric square is actually a giant computer. However, it is a very slow computer – probably 100 times times slower than today's average computer, and very expensive. The "Ether-square computer" has a similar situation to the 90-generation smartphone. Apart from some very simple things, it can hardly do anything.

It doesn't sound very appealing, so why is there so many people flocking to the ether square? This is a very good question. It is no exaggeration to say that the etheric square is sweeping the world, as it is a fully-centralized computer, distributed all over the world. Understand how the etheric block chain works, and see how it assumes the role of a world computer. how the etheric square works.

Like all other block chains, the etheric square requires thousands of people to run a software on their PCs to support the entire network. Each node (computer) in the network runs a thing called the etheric Square virtual machine (Ethereum Machine, EVM). EVM can be imagined as an operating system that understands and executes software written in a particular programming language. Software or applications executed by EVM are called "Smart Contract".

In order to do something on this world computer, you need to pay a certain amount of money. But you are not a regular currency such as dollars or pounds. Instead, it pays for the related costs through the original encrypted currency of the etheric square network called ether (Ether,eth). The ether is almost exactly the same as the Bitcoin, and the only difference is that it is used to pay for the implementation of the intelligent contract on the etheric square.

Either a person or an intelligent contract is regarded as a user on the etheric square. What a man can do on the ether, an intelligent contract can do.

Smart contracts look just like anyone else on the web. They can all send or receive ether, just like any other currency.

But smart contracts are not exactly the same as humans. Unlike the human user, an intelligent contract can also execute a predefined computer program to perform a variety of actions that can be triggered by an event. To feel the power of a smart contract, let's consider an example: the power of a smart contract

Suppose you and I bet on tomorrow's weather, I bet it will be sunny tomorrow, but you bet it's rainy day. Both sides agree that the loser must give 100 dollars to the winning party. So how can we do that and make sure that the loser doesn't cheat? I can think of three different ways: 1. Trust each other

The easiest way is to trust each other. If we are old friends, it is very easy to trust each other. I know where you live, and you know all kinds of embarrassing things about me. But if we are completely strangers, things can get a lot more complicated. I have no reason to trust you, and you have no reason to trust me. 2. Sign a legal agreement

Another plausible option would be to formalize our bets on a legally binding agreement. We both sign an agreement that defines all the details – including what happens if the loser violates the agreement.

This agreement will make it incumbent upon us to pay the winning party, but it is of no practical use, because the cost of enforcing the agreement legally is much higher than the price of the wager. 3. Ask a mutual friend to help

We can find a friend who is trustworthy on both sides, and then give this friend 100 dollars for safekeeping. The next day, he will check the weather, and then put all 200 dollars to the betting on the winning side. Very simple and convenient, except for one thing: What if the two trusted friends put the money away?

Now we have three different schemes for betting, but each has its drawbacks: because it's a stranger, we can't trust each other. Enforcing a protocol is so expensive that it does not have any practicality. Asking for a common friend also encounters a problem of trust.

The intelligent contract of the etheric Square is to save the problem. A smart contract is like a trusted mutual friend, but it's written in code. We can write a contract on the ether, which receives 100 dollars of input from both of us, and then, on the following day, checks the weather through an open weather API and transfers all the ether to the winning side.

Once a contract is written, it can no longer be edited or modified. Therefore, you can guarantee that whatever the contract is, it will be executed unconditionally.

However, how the smart contract is implemented. What's the connection to the block chain? How a smart contract is associated with a block chain.

No matter when an intelligent contract is executed, it is recorded as a transaction on a block. In a nutshell, a deal on an Ethernet square looks like this:

In addition to the last Data, the other fields I believe you can see what you are doing at a glance. It is this data field that makes the etheric square unique. Data is used to record the creation and execution of smart contracts, just as transactions are recorded. In the etheric square block chain, any one block may contain the following three kinds of transactions: 1. Ordinary transactions transferred from one person to another

These ordinary transactions are like Bitcoin trading. If you send the ether directly to your friend, then the data field is empty and the transaction is a normal transaction.

2. Only the sender has no receiver

If there is no recipient in a transaction, this means that the transaction uses the contents of the data field to create an intelligent contract on the network. The data field contains code that is like other users on the network.

3. Transfer the ether to an intelligent contract

Whenever a user (or a smart contract) wants to execute an intelligent contract, he/she creates an intelligent contract transaction and places an execution instruction in the data field.

As with other block chains, the three events mentioned above will be posted to the network, and everyone on the network will record it. In addition to logging, each node also performs a smart contract to synchronize their EVM status with the rest of the network.

Each node executes part of the software, so the entire network is like a large (but slow) distributed computer. Every time no matter how small the execution, will be recorded on the block chain, permanent existence. Wait a minute, gas is something.

If a user wants to use and execute a smart contract, he or she must pay a fee for executing the smart contract. This fee is given to the node that actually spends the resources such as memory, storage, calculation and power to execute the contract.

In order to calculate the cost of a smart contract, each statement in the contract has a charging standard. For example, if the executed statement uses the memory of the node, the statement will have a price. If you execute a statement that uses a node's hard disk storage, these statements are another price. Here, the unit that defines the cost is called gas. In the end, gas is converted into ether (ETH) through the exchange rate.

Whenever you execute an intelligent contract, you must define a maximum amount of gas that can be spent. When an intelligent contract is executed or a gas limit is reached, execution is halted. This is to avoid an infinite loop in the smart contract, preventing some repetitive statements from occurring that cause the program to stall.

Because of some bugs in the programmer, it is likely to cause such a thing to happen. So each time it repeats, it consumes some of the allocated gas, so there is no such thing as an infinite loop. There is no need for programmer errors to cause a node to crash at execution time. Using gas solves the problem. This is the ether square .

The ether is not just a cryptographic currency for trading, its real value is its purpose-the purpose of the Ether square is to allow people to use distributed world computers supported by thousands of of nodes.

Of course, because each statement must be performed by each node in the network, the decentralized distributed computer becomes slow and expensive. However, the slow in this is compared with WHO. is a server that is faster, but is controlled by a centralized control.

In order to be able to enjoy the low cost of the centralized computer, we surrendered our control. But if the central server is down or hacked, then all clients connected to it will hang up. and a decentralized distributed computer, only if each node is stopped working, it will be dead. In other words, this makes it never go down. No matter where, as long as there is a network, there is an Ethernet square.

Original: WTF is Ethereum? The ultimate guide to understand why Ethereum are not just another.

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.