Blockchain Enthusiast (qq:53016353)
Some people say that digital money is too difficult to deal with, so we wrote this article to help you learn how to write smart contracts and applications using digital currencies, Consensys. The tools, wallets, applications, and entire ecosystems used here are still in development, and they will work better in the future.
The first section outlines the key concepts, several large digital currency clients, and the programming language used to write the smart contracts.
The second section discusses the overall workflow, as well as some of the DAPP frameworks and tools that are currently popular.
Part three focuses on programming, and we'll learn how to use truffle to write tests and build Dapp for smart contracts.
The first part. Overview
If you are completely unfamiliar with the concept of cryptocurrency, such as bitcoin and how it works, we recommend that you take a look at the first few chapters of Bitcoin book by Andreas Antonopoulos and then read the digital Money white paper.
If you think the chapters in the White paper are too obscure, you can also get to know the digital currency directly. Developing in digital currencies does not require you to understand all those "cryptographic economics computer Science" (Crypto economic computer sciences), and much of the white paper is about the digital currency's improvements to the Bitcoin architecture.
Beginner Tutorials
Ethereum.org provides an official beginner's introductory tutorial, as well as a tutorial on token contracts and crowdfunding contracts. The contract language solidity also has official documentation. Another good piece of information for learning smart contracts (and my entry) is dappsforbeginners, but it may be a bit out of date.
The purpose of this article is to complement the above information and to introduce some basic developer tools that make it easier to get started with digital currencies, smart contracts and build dapps (decentralized apps, distributed applications). I will try to explain in my own (still novice) understanding what each step of the workflow is doing, and I get a lot of help from Consensys's cool developers.
Basic concepts
Knowing these nouns is a good place to start:
Public key cryptography System. Alice has a public key and a private key. She can create a digital signature with her private key, and Bob can use her public key to verify that the signature was actually created with Alice's private key, that is, Alice's signature. When you create a digital currency or Bitcoin wallet, that long 0xdf ... The 5f address is essentially a public key, and the corresponding private key is saved somewhere. An online wallet similar to Coinbase can help you keep your private key, and you can keep it for yourself. If you lose the private key of a wallet that has money, you will lose that money forever, so you'd better make a backup of the private key. "It is very painful to learn this by stepping on the pit," said the experienced.
Point-to-point network. Just like BitTorrent, all the nodes in the digital-currency distributed network have equal status and no hub servers. (In the future there will be semi-centric hybrid services for users and developers to facilitate, as we'll talk about later.) )
Block chain. Blockchain is like a world-only book, or database, that records all the trading history in the network.
Digital currency virtual machine (EVM). It allows you to write more powerful programs in digital currencies (you can also write scripts in bitcoin). It is sometimes used to refer to the digital currency blockchain, which is responsible for performing smart contracts and everything.
Node. You can run a node, read and write a digital currency blockchain, or use a digital currency virtual machine. The full node needs to download the entire chunk chain. The light node is still under development.
Proof of workload. The miners are always competing to solve some mathematical problems. The first to solve the answer (figure out the next chunk) will receive the aether as a reward. All nodes are then updated with their own blockchain. All miners who want to work out the next chunk have to keep up with the rest of the nodes and maintain the power of the same blockchain, so the entire network can always reach a consensus. (Note: The digital currency is planning to turn to a proof of entitlement system (POS) without miners, but that is not covered in this article.) )
Ether coins. Abbreviation ETH. A real digital currency that you can buy and use. Here is the chart of one of the exchanges that can trade the etheric currency. At the time of writing this article, 1 etheric coins were worth 65 cents.
Gas. (petrol) The implementation of the program in the digital currency and the preservation of data will consume a certain amount of etheric currency, gas is converted from the ether currency. This mechanism is used to ensure efficiency.
Dapp. The digital Money community calls applications based on smart contracts a decentralized app. The goal of Dapp is (or should be) to have a friendly interface to your smart contract, plus something extra, such as IPFs (a central network that can store and read data, not from a digital money team but with a similar spirit). Dapp can run on a centralized server that can interact with a digital currency node, or it can run on any digital currency equal node. (Take a minute to think about it: Unlike normal web sites, Dapp can't run on a regular server.) They need to commit transactions to the blockchain and read important data from the blockchain rather than the centralized database. Compared to a typical user login system, the user may be represented as a wallet address while other user data is stored locally. Many things will have different architectures than the current Web application. )
If you want to see how these concepts can be understood from another novice perspective, read just enough Bitcoin for Ethereum.
Digital currency client, Smart contract language
Writing and deploying smart contracts does not require you to run a digital currency node. The following is a list of browser-based Ides and APIs. But if it is for learning, you should run a digital currency node to understand the basic components, not to mention running the nodes.
Clients that are available to run the digital currency node
Digital currencies have many client implementations in different languages (i.e., multiple ways to interact with digital money networks), including C + +, Go, Python, Java, Haskell, and more. Why so many implementations are needed. Different implementations can meet different requirements (for example, the goal of the Haskell implementation can be mathematically validated), making the digital currency more secure and enriching the entire ecosystem.
While writing this article, I used the Go language implementation of the client Geth (go-ethereum), other times also use a tool called TESTRPC, which uses the Python client pyethereum. These tools are used in the following examples.
Note: I've used a C + + client, and I'm still digging with the Ethminer component and the Geth, so these different components work together.
About mining: Digging is interesting, a bit like taking care of your indoor potted plant, and a way to understand the whole system. Although the current price of the etheric currency may not even be able to fill the electricity bill, but who knows later. People are creating a lot of cool dapp that could make digital money more popular.
Interactive consoles. After the client runs, you can synchronize the blockchain, build the wallet, and send and receive the etheric currency. One way to use Geth is through the JavaScript console (JavaScript console, like the one you press F12 in Chrome, just run in the terminal). You can also use the curl-like command to interact with the client through JSON RPC. The goal of this article is to take everyone through the process of dapp development, so this piece is not much to say. But we should keep in mind that these command-line tools are debugging, configuring nodes, and using wallets.
You run the node in the test network. If you are running the Geth client on the official network, it will take quite a while to download the entire blockchain to sync with the network. (You can determine whether you have synchronized by comparing the last block number printed in the node log and the latest block listed on stats.ethdev.com.) Another problem is that running a smart contract on the official network requires a real etheric currency. There is no problem with running nodes on the test network. There is no need to synchronize the entire blockchain at this time, create a private chain of their own tick, for development is more time-saving.
Testrpc. With Geth you can create a test network, and another way to create a test network faster is to use TESTRPC. TESTRPC can help you create a pile of test accounts with funds at startup. It runs faster and is therefore more suitable for development and testing. You can start from Testrpc, and then move on to the test network created by Geth as the contract slowly takes shape-the startup method is simple, just specify a networkid:geth--networkid "12345". This is TESTRPC's code warehouse, and we'll talk about it later.
Next we talk about the available programming languages, and then we can start to really program.
Programming language for writing smart contracts
It's good to use solidity. There are several languages available to write smart contracts: a bit like JavaScript solidity, the file extension is. Sol. And Python close to the serpent, with the file name ending with. SE. There are also lll like Lisp. Serpent has been popular for some time, but now the most popular and most stable to be considered solidity, so with solidity good. I heard you like python? With solidity.
Solc compiler. After writing a smart contract with solidity, you need to compile it with SOLC. It is a component from the C + + client implementation (again, different implementations are complementary), here is the installation method. If you do not want to install SOLC you can also use the browser-based compiler directly, such as solidity real-time compiler or Cosmo. The section on programming later assumes that you have installed the SOLC.
Note: The digital currency is in active development, and sometimes the new version will be out of sync. Make sure you're using the latest dev version, or a stable version. If you have a problem, you can go to the gitter chat room or forums.ethereum.org on the digital currency project and ask what version the other person is using.
Web3.js API. Once the solidity contract is compiled and sent to the network, you can use the Web3.js JavaScript API of the digital currency to invoke it and build a Web application to interact with.
These are the basic tools needed to write smart contracts on digital currencies and build dapp that interact with them.