Here’s what you need to know when you start exploring blockchain development.

I. Introduction of DApp

What is a DApp?

DApp is a Decentralized Application. In some ways, Bitcoin is arguably the first DAPP to emerge, as it is completely open source, offers rewards to contributors, is not controlled by a central body, and uses blockchain as the underlying technology. Blockchain, as an infrastructure, provides a distributed decentralized trusted database on which people can build a variety of applications for different scenarios. Simply put, DApps work the same way as regular apps except that they are completely decentralized. Dapps run by their own nodes, like the Ethereum network itself, and don’t rely on any centralized server. Dapps are decentralized and run completely automatically. Currently dApps usually refer to related applications based on smart contracts on Ethereum or EOS.

DApp operation principle

The underlying blockchain development platform of DApp is just like the iOS and Android systems of mobile phones. It is the underlying ecological environment of various DApps. DApp is a variety of distributed applications derived from the underlying blockchain platform, and is also the basic service provider in the blockchain world. Just like apps are for iOS and Android.

What is a smart contract?

If you think of a blockchain as a database, a data source, a smart contract is basically a script for database operations that determines how you store data on the blockchain, how you modify the data.

DApp application cases

Check out the latest developments in the DApp industry here: www.stateofthedapps.com/

The cat cryptokitties encryption

Fomo3D

Smart Contract Development

Introduction to the

A smart contract is a collection of code (its function) and data (its state) that exists at a specific address on the Ethereum blockchain. Smart contract accounts can pass information between each other and perform Turing-complete calculations. Smart contracts run on a blockchain called ethereum Virtual Machine (EVM) bytecode (Ethereum’s unique binary format).

Smart contracts are written in high-level languages such as Solidity, compiled into byte code and uploaded to the blockchain.

The smart contract development process generally includes the following steps:

  • Writing smart contracts (e.g. based on solidity)
  • Test smart contracts and perform functional tests on the test network or private chain
  • Compile and publish contracts to deploy them on the chain
  • Manipulate contracts, using interfaces such as web3.js, to invoke and manipulate smart contracts by accessing their addresses.

Structure diagram:

Smart contract development flow chart:

Solidity

Solidity is a high-level language with a JavaScript like syntax. It is designed to generate the Ethereum VIRTUAL machine code in a compiled manner.

Code snippet:

pragma solidity ^0.422.;

contract helloWorld {
 function renderHelloWorld () public pure returns (string) {
   return 'helloWorld'; }}Copy the code

ERC-20

The most famous smart contract, you’ve probably heard of, is the ERC20. Erc-20 is a standard protocol for tokens, and simply put, any ERC-20 token is instantly compatible with ethereum wallets (just about every wallet that supports Ethereum, including MIST, imToken, etc.), and since exchanges already know how these tokens operate, they can easily integrate them. This means that, in many cases, these tokens can be traded immediately.

An ERC-20-based token contains the following interfaces:

contract ERC20Interface {
    function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);
    function transferFrom(address from, address to, uint tokens) public returns (bool success);

    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
Copy the code

Introduction to the Solidity development environment

Below I will run through the Solidity idity development environment and tools for smart contracts, a collection of tools commonly used in smart contract development today.

IDE

Develop Solidity based smart contracts using the following development environment

  • VSCode + Solidity Plugin
  • Remix Solidity IDE (remix.ethereum.org)

Truffle

Truffle is a development framework for the Ethereum-based Solidity language. Itself based on Javascript.

  • Built-in smart contract compilation, linking, deployment and binary management.
  • Automated contract testing under rapid development.
  • Scripted, extensible deployment and publishing framework.
  • Network environment management functions deployed to no matter how many public or private networks
  • Use package management provided by EthPM&NPM, using the ERC190 standard.
  • A direct interaction console that communicates directly with contracts (which can be verified on the command line after writing contracts).
  • Configurable build processes that support tight integration.
  • The Truffle environment supports the execution of external scripts.

Install the Truffle

npm install -g truffle
Copy the code
mkdir myproject && cd myproject && truffle init
Copy the code

Ganache

By using Ganache, you can quickly see how your application affects the blockchain. Details: your account, balance, contract and Gas costs.

Geth

Geth, which stands for Go-Ethereum, is the official wallet client of Ethereum. Geth is command line based. By using Geth and related parameters, we can access ethereum’s public, test, and private networks. In addition to the main network, Ethereum has various test networks. Before using GEth, decide which network you want to access. Geth is the equivalent of starting an Ethereum network node on the machine, but with parameter controls, the node can choose to be either a full node or a light node.

The Geth console provides admin, debug, ETH, Miner, NET, personal, RPC, TXpool, and web3 services and commands. For example, there are these common operations:

  • Eth. BlockNumber Displays the current block height and the total number of blocks
  • Eth. GetBlock (XXX) Displays information about a specific block
  • Accounts View the account address of the current wallet. When you run the private chain network for the first time, there is no account and you need to create one
  • Eth. Coinbase miner’s account, into which rewards are paid when the network mines a new block
  • Personal. NewAccount () Creates an account, prompting you to enter a password, and saves the account in the data/keystore directory with an encrypted private key file
  • Miner.start (threas_number) starts mining if the wallet already has a Coinbase miner account
  • Miner. Miner

Create an account and obtain the balance from the geth command line:

Mist

Mist is Ethereum’s official graphic wallet, which allows users to easily manage accounts, check balances, and send and receive transactions. Another very useful feature of Mist is the ability to compile and deploy Solidity smart contracts.

web3.js

Web3.js provides Web3 objects that encapsulate a set of methods that can be used to manipulate smart contracts. In the underlying implementation, it communicates with the local node GETH through RPC calls.

Geth itself can interact with the contract, and web3.js encapsulates another layer, so that we can use JS programs to interact with the contract, convenient development.

The introduction of

npm install web3
Copy the code

The interaction flow of Ethereum through Web3 is roughly as follows:

conclusion

With the popularity of blockchain in recent years, DApp has been pushed to the forefront of the storm. This paper roughly introduces the technical points involved in DApp from the perspective of technology. The following articles can share some specific cases of DApp development in more detail, and introduce some DApp Demo and specific development process.


The text/Li Gong

General program monkey, who has been working for 91 and Baidu in mobile Internet for a long time, is now a senior blockchain development engineer, and has learned solid blockchain knowledge in the experience of Leek

This article has been authorized by the author, the copyright belongs to chuangyu front. Welcome to indicate the source of this article. Link to this article: knownsec-fed.com/2018-08-10-…

To see more sharing from the front line of KnownsecFED development, please search our wechat official account KnownsecFED. Welcome to leave a comment to discuss, we will reply as far as possible.

Thank you for reading.