Principle of Ethereum smart contract
DTV share, Ethereum is an open source public blockchain platform with intelligent contract function. It provides decentralized virtual machines to handle point-to-point contracts through its private cryptocurrency, Ethernet. Key points: open source, smart contract function, public chain platform, Ethernet
Thank you for your recommendation. Here I would like to share with you the following:
forsage international crowdfunding, the revolutionary smart contract technology of the new generation platform, originated from the development of Russian technical team, provides distributed market participants with the ability to directly engage in personal and commercial transactions. The smart contract of forsage distributed global shared matrix project is open and can always be viewed on the Ethereum blockchain. These are real smart contracts, which will be implemented on the Ethereum public chain forever without any third party tampering. The global shared matrix project is completely decentralized, aiming to preach Ethereum, so that more players can know Ethereum, smart contracts and forsage code btshijie
what is Ethereum
Ethereum is often compared with bitcoin, but the situation is different. Bitcoin is a kind of cryptocurrency and distributed payment network, which allows bitcoin to be transferred between users
the Ethereum project has a bigger goal. As Ethereum said, "Ethereum is a distributed platform running smart contracts.". These smart contracts run on "Ethereum virtual machine", a distributed computing network composed of all devices running Ethernet nodes
"distributed platform" means that anyone can set up and run an Ethereum node just as anyone can run a bitcoin node. Anyone who wants to run "smart contracts" on nodes must pay the operators of these nodes in ether, which is a cryptocurrency related to Ethereum. Therefore, the person running the Ethernet node provides computing power and gets paid in the Ethernet, which is similar to the way that the person running the bitcoin node provides hash power and pays in bitcoin
in other words, although bitcoin is only a blockchain and payment network, Ethereum is a distributed computing network, and its blockchain can be used for many other things. Details are provided in the Ethereum white paper
what is smart contract
smart contracts are applications that run on Ethereum virtual machines. This is a distributed "world computer" with computing power provided by all Ethereum nodes. Any node providing computing power will pay in ether digital currency as a resource
they are named smart contracts because you can write "contracts" that execute automatically when you meet the requirements
for example, imagine building a KickStarter like crowdfunding service on Ethereum. Someone can set up an Ethereum smart contract to pool funds to others. The smart contract can be written as follows: when $100000 of currency is added to the pool, it will be sent to the recipient. Or, if the $100000 threshold is not reached within a month, all currencies will be returned to the original holder of the currency. Of course, this would use ether instead of dollars
all this will be done according to the smart contract code, which can automatically execute the transaction without the need for a trusted third party to hold the currency and sign the transaction. For example, KickStarter charges 5% above the 5% payment processing fee, which means it will charge $8000 to $10000 for a $100000 crowdfunding project. Smart contracts don't have to pay a fee to a third party like KickStarter
smart contracts can be used for many different things. Developers can create smart contracts to provide functions for other smart contracts, similar to the way software libraries work. Alternatively, smart contracts can simply be used as applications to store information on the Ethereum blockchain
in order to really execute the smart contract code, someone has to send enough Ethernet tokens as the transaction fee - how much depends on the required computing resources. This costs the Ethereum nodes to participate and provide computing power. The global shared matrix project, which is completely decentralized, aims to preach Ethereum and let more players know Ethereum, smart contracts and forsage code btshijie
& quot; A smart contract is a set of promises defined in digital form, including the agreements on which the contract participants can execute these promises& quot;
let's explore the meaning of his definition in more detail
commitment
a set of commitments refers to the (often mutual) rights and obligations agreed by contract participants. These commitments define the nature and purpose of the contract. Take a sales contract as a typical example. The seller promises to deliver the goods and the buyer promises to pay a reasonable price
digital form
digital form means that contracts have to be written into computer-readable code. This is necessary, because as long as the participants reach an agreement, the rights and obligations of smart contract establishment are executed by a computer or computer network
to further explain:
(1) when will the parties to the smart contract reach an agreement? The answer depends on the specific smart contract implementation. Generally speaking, the contract is discovered when the parties are committed to the execution of the contract by installing the contract on the contract host platform< (2) contract execution
& quot; Execute & quot; And the real meaning of it also depends on implementation. Generally speaking, implementation means active implementation through technical means
(3) computer readable code
in addition, the contract needs specific & quot; Digital form & quot; Very much depends on the agreement that the parties agree to use
protocol
protocol is technical implementation, on this basis, the contract commitment is realized, or the contract commitment is recorded. Which agreement to choose depends on many factors, the most important of which is the nature of the assets being traded ring the performance of the contract
take the sales contract as an example. Suppose that the participants agree to pay in bitcoin. The chosen protocol will obviously be bitcoin protocol, on which the smart contract will be implemented. Therefore, the contract must use & quot; Digital form & quot; It's bitcoin scripting language. Bitcoin scripting language is a non Turing complete, imperative, stack based programming language, similar to forth.
although bitcoin can also write smart contracts, the syntax supported by bitcoin is only related to transactions, and there are limited things it can do
therefore, when it comes to writing smart contracts, it usually refers to Ethereum blockchain that supports the execution of Turing complete programs.
The smart contract has been written for a long time
if they can add changes, the description is centralized
the contract is written into the Ethereum smart contract, which is a contradiction sentence
the financial customer service doesn't understand, which is very unreliable
community sites
a total of 22 weeks, divided into five stages,
the first stage is 4 weeks, go language foundation and network concurrency, learning the introctory go language,
the second stage is 4 weeks, go language practical web development, crawler development, cryptography, consensus algorithm, realizing lightweight public chain, learning the website and crawler that can develop golang, Achieve lightweight blockchain
stage 3, 4-week Ethereum source code analysis and smart contract DAPP development, master Ethereum core and smart contract development, as well as blockchain,
stage 4, 4-week super ledger, bitcoin EOS, source code analysis and smart contract practice, master super ledger development, cat bitcoin, bifurcated EOS after learning, As well as DAPP development of smart contract
phase 5, 6-week project practice, five enterprise level projects, and one year of blockchain project experience after learning
from the characteristics of the language itself, go is a very efficient language, which highly supports concurrency. Go language itself pays more attention to distributed system, and concurrency processing is relatively good, such as advertising and search, That kind of high concurrency server
go language advantages:
excellent performance, can be directly compiled into machine code, does not rely on other libraries, go is extremely fast. Its performance is similar to Java or C + +
concurrency is supported at the language level, which is the biggest feature of go. It is born to support concurrency, and go is the concurrency supported in gene, which can make full use of multi-core and make it easy to use concurrency
the built-in runtime supports garbage collection, which is one of the features of dynamic language. Although GC is not perfect at present, it is enough to cope with most of the situations we can encounter, especially GC after go1.1
it's easy to learn. The authors of go language all have the gene of C, so go naturally has the gene of C. There are 25 go keywords, but the expressive ability is very strong. It almost supports most of the features you've seen in other languages: inheritance, overloading, object, etc
rich standard libraries, go has built a large number of libraries, especially the network library, which is also my favorite part< As like as two peas, br / > built-in powerful tools, Go language is built with many tools chain, the best should be gofmt tools, automatic formatting code, make team review become so simple, code format is exactly the same, it is very difficult to think differently.
cross platform compilation and fast compilation. Compared with the sluggish compilation speed of Java and C + +, the fast compilation time of go is a major efficiency advantage
disadvantages of go language:
package management: package management of go language is absolutely not perfect. By default, it has no way to make a specific version of the dependency library, nor can it create replicable builds. In contrast, python, node and Ruby all have better package management systems. However, with the right tools, the package management of go language can also perform well
lack of development framework: go language does not have a major framework, such as Ruby's rails framework, Python's Django framework or PHP's laravel. This is a heated discussion in the go language community, because many people think that we should not start with using frameworks. This is true in many cases, but if you just want to build a simple crud API, it's much easier to use Django / djrf, rails laravel, or Phoenix
exception handling: go language can help developers deal with compilation errors by simply returning errors (or call stack) through functions and expected calling codes. Although this method is effective, it is easy to lose the scope of the error, so it is difficult to provide meaningful error information to users. Error package can solve this problem by allowing us to add context and stack trace to return error
another problem is that we may forget to handle errors. Static analysis tools such as errcheck and megacheck can avoid these errors. Although these solutions are very effective, they may not be the right way.
do you remember what the consensus mechanism of bitcoin is? The consensus mechanism of bitcoin is pow. To put it simply, the more work you do, the higher the amount of computation you pay, the more likely you will be the first to find the correct hash value, and the more likely you will be rewarded with bitcoin
however, there are some defects in the pow of bitcoin, that is, it is too slow to process transactions, and miners need to constantly collide hash values through calculation, which is costly and inefficient. Friends who are interested in blockchain knowledge should see such a saying:
in order to make up for the deficiency of bitcoin, Ethereum has proposed a new consensus mechanism, called POS (this is the abbreviation of English, which means "proof of equity", also translated into "proof of equity")
POS simply means the same as its literal meaning: equity, equity. The more currency you hold, the more equity you have, the higher your equity
Ethereum's POS means that the more money you hold, the longer you hold it, the less difficult it will be to calculate and the easier it will be to mine
in the initial setting of Ethereum, Ethereum hopes to build a relatively stable system by using POW in the early stage, then graally adopt POW + POS, and finally completely transition to POS. So, it's true that the consensus mechanism of Ethereum is POS, but POS is only a plan or goal at the beginning of Ethereum's release. At present, Ethereum has not yet transitioned to POS, and the consensus mechanism adopted by Ethereum is still pow, that is, the pow of bitcoin, but it is slightly different from the pow of bitcoin
the amount of information here is a bit large,
the first information point is that the consensus mechanism currently adopted by Ethereum is also pow, but it is slightly different from the pow of bitcoin. So, what's the difference between the pow of Ethereum and bitcoin: in short, the mining difficulty of Ethereum can be adjusted, but the mining difficulty of bitcoin can't be adjusted. Just like our college entrance examination, because the teaching situation and the number of students in different provinces are not the same, so the college entrance examination is divided into national papers and provincial independent proposition
Ethereum said that I am in favor of the topic by region. Bitcoin said: No, it must be the same volume in the whole country. The difficulty is the same for everyone
the popular explanation is that bitcoin uses computer computing power to do a lot of hash collisions, enumerate various possibilities to find a correct hash value. The Ethereum system has a special formula to calculate the difficulty of each block. If a block is verified faster than the previous block, Ethereum protocol will increase the difficulty of the block. By adjusting the block difficulty, the time needed to verify the block can be adjusted
according to the Ethereum protocol, the dynamic adjustment method of difficulty is to make the time interval of creating new blocks in the whole network 15 seconds, and the network uses 15 seconds to create blockchain. In this way, because the time is too fast, the synchronization of the system is greatly improved, and it is difficult for malicious participants to launch 51% (that is, more than half) of the computing power to modify historical data in such a short time
the second information point is: in the initial setting of Ethereum, we hope to achieve the transition from POW to
POS through phased upgrade
dating back to 2014, at the beginning of Ethereum's launch, the team announced that the launch of the project would be divided into four stages, namely, Froniter, homestead, metropolis and serenity. In the first three stages, the consensus mechanism adopts pow (workload proof mechanism), and in the fourth stage, it switches to POS (equity proof mechanism)
on July 30, 2015, the first phase "frontier" of Ethereum was officially released. This phase is only suitable for developers. Developers can write smart contracts and decentralized application DAPP on Ethereum network, and miners begin to enter Ethereum network to maintain network security and get Ethereum coins. The leading-edge version is similar to the beta version, proving whether the Ethereum network is reliable or not
on March 14, 2016, Ethereum entered the second stage of "homeland". In this stage, Ethereum provides the wallet function, so that ordinary users can easily experience and use Ethereum. There is no obvious technology improvement in other aspects, but it shows that Ethereum network can run smoothly
in September 2017, Ethereum has reached the third stage of "metropolis"“ "Metropolis" is composed of Byzantine and Constantinople. The goal of this stage is to introce the hybrid chain mode of POW and POS, so as to prepare for the smooth transition from POW to POS. This is the latest popular "Ethereum Constantinople upgrade". In the Constantinople upgrade, Ethereum will make some changes to the underlying protocols and algorithms to lay a good foundation for the implementation of POW and
POS
how much reward will Ethereum get for mining? Miners who win the block creation competition will get the following income:
1. Static reward, 5 ethereums
2. The fuel cost in the block, i.e. gas, we talked about in the last issue
3. As a part of the block, it includes the extra reward of "Uncle block". Uncle is uncle of uncle, and each uncle block can get 1 / 32 of the mining reward as a reward, that is, 5 times 1 / 32, which is equal to 0.15625 ethereums. Here, let's briefly explain the concept of "TERT block". The concept of "TERT block" was proposed by Ethereum. Why should we introce the concept of TERT block? This also starts with bitcoin. In the bitcoin protocol, the longest chain is considered absolutely correct. If a block is not part of the longest chain, it is called a "orphan block". An isolated block is a block, which is also legal, but it may be found later, or the network transmission is slower, and it does not become part of the longest chain. In bitcoin, the solitude is meaningless and will be discarded later, and the miners who find the solitude will not receive mining related rewards
however, Ethereum does not think that isolated blocks are worthless, and Ethereum system will give rewards to miners who find isolated blocks. In Ethereum, isolated blocks are called "Uncle blocks", which can contribute to the security of the main chain. Ethereum's ten second block interval is too fast, which will rece the security. By encouraging the use of tertiary blocks, the main chain can obtain more security guarantees (because the isolated block itself is legal). Moreover, paying the tertiary block can also stimulate the miners to actively mine and actively use tertiary blocks. Therefore, Ethereum thinks that it is valuable.