Blockchain circle

One stop hot information platform

About us:

Blockchain circle provides the latest information about blockchain, digital currency, digital wallet, exchange, metauniverse, bitcoin, Ethereum, contract, financial management and so on, and always pays attention to the latest market...

What programming languages are involved in the introduction of blockchain technology?

Time : 20/10/2021 Author : bjf5lg Click : + -
        However, because Ethereum and hyperledger fabric support the go language best, the go language must be learned. Statement: it is estimated that all Zhihu ers who see this question want to get started with the blockchain, so this answer is mainly an introduction to the entry level. It is only an introduction to the entry level, and is not suitable for the promotion and learning of blockchain practitioners. There are many definitions of blockchain, and everyone has different opinions. There is no consensus in the industry. Everyone has his own Hamlet in his heart. So there is no definition here. You can also refer to other answers. Well, I mainly recommend some learning materials about the concept of blockchain. After reading the materials I recommend, you should have your own understanding of this technology:.
 
        Bitcoin white paper: a peer-to-peer electronic cash system (bitcoin white paper: a peer-to-peer electronic cash system Babbitt). The principles of cryptography, the basic concepts of bitcoin, the consensus mechanism, the current situation of blockchain, the problems in the application of blockchain, including the relatively new side chain, are all discussed. I didn't find this book in JD / TB / DD / AMZ before, so I attached the Chinese electronic version: (link: 7 password: uq7g) for invasion and deletion. As the CTO of Zhigui, Mr. Chen Chang remembers that the previous ink chain was based on hyperledger fabric, so this book gives a thorough explanation of hyperledger related open-source products.
 
        I have worked in the field of smart contracts for 4 years, mainly on the bitcoin blockchain. Some of my projects include proof of existence, bitcore and streamium In the past month, I explored developing on the Ethereum platform. I decided to make a short guide for programmers who want to learn Ethereum development in the future. The manual is divided into two parts: how to start the development of Ethereum smart contract and a brief description of smart contract security. This guide assumes that you have some basic technical background of cryptocurrency and blockchain. If you don't, I suggest going through Andreas antonopoulos's mastering bitcoin, consensys's just enough bitcoin to understand Ethereum, or at least watching Scott Driscoll's short film.
 
        In order to continue reading, you need to understand the public and private keys, why blockchain needs miners, how to reach a decentralized consensus, and the concepts of transaction scripts and smart contracts. The other two important concepts you need to understand before you start to develop Ethereum are Ethereum virtual machine and gas. Ethereum aims to become a smart contract platform. Its origin can be traced back to vitalikbuterin's comments on the limitations of bitcoin as a smart contract platform. Ethereum virtual machine (EVM) is the place where Ethereum smart contracts are executed. Compared with bitcoin, it provides a more expressive and complete language for writing contracts.
 
        In fact, it is a Turing complete programming language. A better analogy is that EVM is a distributed world computer that executes smart contracts. Since smart contracts are executed by EVM, there must be a mechanism to limit the resources occupied by each contract. Each operation in EVM is actually executed by all nodes at the same time. This is why gasoline (gas) is needed. An Ethereum contract code transaction can trigger expensive operations such as data reading and writing, cryptology primitives, and transferring (sending information to) other contracts. Each such calculation is based on the price measured by gasoline. The gasoline unit consumed in each transaction needs to be paid in Ethereum, which is calculated according to the exchange rate of gasoline and Ethereum that changes at any time.
 
        The corresponding price will be deducted from the Ethereum account that submitted the transaction request. At the same time, the upper limit parameter will be set for the available gasoline in each transaction to prevent the programming error from depleting the funds in the account. Click here to read more about gasoline. Well, you already know the basic ones. Let's hurry up and write the code. In order to start developing Ethereum app (or DAPP, short for decentralized application, as many people like to call it), you need to install a client to access the main network. It will become a window for you to enter the distributed network and provide a way to observe the blockchain, where all EVM (Ethereum virtual machine) states are displayed.
 
        There are many clients compatible with the terms. The most popular is geth, which is implemented in go language. But it is not the most developer friendly client. The best choice I've found so far is the testrpc node (yes, it's poorly named). Believe me, it will save you a lot of time. Install it and run it:. You should run & lsquo; testrpc’, And keep it running throughout your development. Every time you run testrpc, it will generate 10 new addresses containing the simulation test funds for your use. This is not real money. You can safely use these to carry out any experiments without the risk of losing money.
 
        The most popular language for writing smart contracts in Ethereum is solidity, so we will use this language. We will also use truffle development framework, which will help create smart contracts, compile, deploy and test. Let's get started. Truffle will generate a file required for the demonstration project, including metacoin, an example of a token contract. You should be able to compile the demonstration contract by running the trufflecompile command. Then, you need to use & lsquo; trufflemigrate’ Instructions to deploy the contract in the simulated network.
 
        In this guide, we will write a proof of existence only contract. It is to create an electronic justice authority that stores the hash of documents used to prove the existence. Use & lsquo; trufflecreate:contract’ Let's start. We will start with a simple but error prone code and move towards a better solution. This is a definition of a solidity contract, which is a bit like a class in other languages. There are States and functions in the contract. It is important to distinguish between the two functions that may occur in a contract.
 
        Read only (constant) functions: these functions do not change any state. They just read the state, calculate, and return the value. Because these functions can be solved locally in each node, they do not cost any gas. They are used & lsquo; contant’ Key words are marked. Transaction functions: these functions change the status and transfer funds. Because these changes need to be reflected in the blockchain, the execution of transaction functions requires submission of transactions to the network, which will consume gas. There is one function for each of the two functions in our contract, which has been marked in the notes.
 
        In the next paragraph, we will see how the types of functions we use will change our interaction with smart contracts. This simple version only stores one proof at a time, using the data type byte 32 or 32 bytes, which is the same size as the sha256 hash. Transaction function & lsquo; notarize’ Allow us to change the contract status variable & lsquo; proof’ The hash of a file is stored in. This variable is a public variable, which is the only way for the user of our contract to verify whether a file is fair. We'll do it ourselves later, but first.
 
        Let's deploy proofofexistence1 to the network! This time, you need to edit the migration file (migrations / 2_deploy_contracts. JS) to let truffle deploy our new contract. Replace the content with the following:. You can also selectively delete the statements about convertlib and metacoin, which we won't use again. To run this move again, you need to use the restart tab to make sure it runs again. Now that we have deployed the smart contract, let's play with it! We can send information to it or read its public state through function calls.
 
        We complete it through truffle console:. Note that all function calls will return a promise. When the promise is solved, if we want to verify it, we can pass & lsquo then(console.log)’ To output. The first thing we need to do is to get an expression of our deployment contract and store it in a & lsquo; poe’ Among the variables of. Then we call the trading equation & lsquo; notarize’, This involves a state change.
 
        When we call a transaction equation, we get a promise that is converted into a transaction ID, not the value returned by the function. Remember that in order to change the EVM state, we need to consume gas and submit a transaction to the network. This is why we get the transaction ID as the result of promise, from the transaction that changes the status. Here, we are not interested in the transaction ID, so we can discard the promise. However, when we actually write an app, we want to save it to check the corresponding transactions and catch errors. Next, we call the read-only (constant) function & lsquo; calculateProof‘. Remember to use & rsquo; constant‘ Keyword to mark your read-only function, otherwise truffle will try to create a transaction to execute this function.
 
        This is what we told truffle that we did not interact with the blockchain but just read. Through this read-only function, we will get & rsquo; Anamazingidea‘ Sha256 of the file. We now need to compare this with the status of our smart contract. To check whether the state change is correct, we need to read & lsquo; Proof’ This public state variable. To get the value of a public state variable, we need to call a function with the same name, which will return a promise.
 
        This time, the output hash value is consistent, so everything is as we expected:). As you can see from the above clip, our first version of existence proof smart contract seems to work! good job! But it can only register one file at a time. Let's make a better version. Let's modify the contract to support multiple document validation. Copy the original file to a new file named contracts / proofexistence2.sol, and take the following changes. The main changes include: we put & lsquo; proof’ The variable becomes an array of bytes32 and is named & lsquo; proofs’, We make it private, and then add a function to check whether a file is fair by looping through the array.
 
        This version is better than the first one, but there are still some problems. Note that every time we want to check whether a file has been fairly outdated, we need to cycle through all existing & lsquo; proofs’。 A better structure for storing proofs would be a map. Fortunately, solidity supports mapping structures, which are called mappings in this language. Another improvement we will make in this version of the code is that we will remove those redundant comments that identify read-only or transactional functions.
 
        I think you know all this now:) the following is the final version. I think it should not be difficult to understand, because it is a little changed from the previous version:. This looks good enough. It runs no different from the second version. Remember to run & lsquo; again while updating the migration file; trufflemigrate--reset’ Let me test it. All the code in this tutorial can be found here. After you use testrpc to test your contract on the simulated network, you can test your contract on the real network! This requires you to have a real testnet / livenet Ethereum client.
 
        Click here for instructions on how to install geth. During the development process, you should run your node in testnet mode, so that you can carry out all tests without losing real money. The testnet mode (also called morden in Ethereum) is basically the same as the real Ethereum, but the Ethereum token here has no monetary value. Don't be lazy. Remember to always develop in testnet mode. If you lose Ethereum due to programming errors, you will regret it very much. Run geth in testnet mode and open the RPC server:.
 
        This will open a controller where you can enter the basic password to control your node / client. Your node will start downloading the testnet blockchain. You can download the testnet blockchain on eth Check the download progress on blocknumber. While downloading the blockchain, you can still run the password. For example, let's set up an account: (remember the password!). Let's send some Ethereum in the past and check the balance. You can get free testnet Ethereum here: zerogox / Ethereum / Wei_ faucet. Just copy and paste the address you just generated, and this faucet will send you an Ethereum.
 
        To query the balance, run the following code:. It will tell you that there is no balance because you have not synchronized with the whole network. While you are waiting, go to the testnet block explorer to check the balance. There, you can also see the highest number of blocks in testnet (1355293 at the time of writing this). You can compare this information with eth The information of blocknumber is combined to determine whether your node has completed synchronization. Once your nodes are synchronized, you can start deploying your contracts on testnet through truffle.
 
        First, unlock your master geth account so that truffle can use it. Make sure there is some balance in it, otherwise you will not be able to push the new contract to the network. Get ready! If one of these two
 
        
Previous:Our district works with Jinjiang District of Chengdu to accelerate the development of blockchain industry
Next:No more

Related articles:



© 2005-2032 | Blockchain Circle & & All Rights Reserved    Sitemap1 Sitemap2 If there is infringement, please contact us at: