Author

Topic: Ethereum Development Tutorial (Read 107 times)

newbie
Activity: 90
Merit: 0
April 24, 2018, 04:08:53 AM
#3
Programming language: Solidity
The default programming language for smart contracts is Solidity, and the file extension ends with .sol.
Solidity is a language similar to JavaScript, used to develop contracts and compiled into Ethereum virtual machine byte code.
There is also Serpent, a smart contract development language that looks like Python, but it is recommended that you use Solidity.
Browser-Solidity is a browser's Solidity IDE. You can check it out. We will introduce Solidity in more articles later.
Operating Environment: EVM
Etherem Virtual Machine (EVM) Ethereum Virtual Machine operating environment for the Ethereum Smart Contract.
Solidity is like EVM, just like the relationship with JVM, so everyone is easy to understand.
The Ethereum virtual machine is an isolated environment. The code running inside EVM cannot be connected to the outside world.
The EVM runs on the Ethereum node. After we deploy the contract to the Ethereum network, the contract can be run on the Ethereum network.
Compilation of the contract
The Ethereum virtual machine runs on the contract bytecode. We need to compile the contract before deployment. We can choose Browser-Solidity Web IDE or solc compiler.
Contract deployment
Ethereum clients (wallets) are often used when developing applications on Ethereum. Usually we are in the development, generally do not contact the concept of the client or wallet, what is it?
Ethereum client (wallet)
Ethereum client, in fact, we can understand it as a developer tool, it provides account management, mining, transfer, smart contract deployment and execution functions.
EVM is provided by the Ethereum client
Geth is a typical client used to develop Ethereum, based on Go language development. Geth provides an interactive command console that contains Ethereum's various functions (APIs).
The console of the Geth console and the Chrome browser developer tool are similar, but they run in the terminal.
In contrast to Geth, Mist is an Ethereum client with a graphical user interface.
How to deploy
The deployment of a smart contract refers to publishing the contract bytecode to the blockchain and using a specific address to identify the contract. This address is called a contract account.
Ethereum has two types of accounts:
External account
This type of account is controlled by a private key (controlled by a person) and no code is associated with it.
Contract account
Such accounts are controlled by their contract codes and have codes associated with them.
Unlike Bitcoin, which uses a UTXO design, Ethereum uses a simpler account concept.
Both types of accounts are the same for EVM.
The difference and relationship between the external account and the contract account is such that an external account can send a message to another external account or contract account by creating and using its own private key to sign the transaction.
Transferring messages between two external accounts is a value transfer process. But the message from the external account to the contract account will activate the contract account code, allowing it to perform various actions (such as transfer tokens, write internal storage, dig out a new token, perform some calculations, create a new contract, etc. Wait).
Only when the external account issues an order, the contract account will perform the corresponding operation.
The contract deployment is to deploy the compiled contract bytecode to the Ethereum blockchain in the form of a transaction sent by an external account (after the actual miner had left the block, it was actually deployed successfully).
run
After the contract is deployed, only the message (transaction) needs to be sent to the contract account when the method for calling this smart contract needs to be called. After the message is triggered, the smart contract code will be executed in the EVM.
Gas
Similar to cloud computing, the resources that occupy the blockchain (regardless of simple transfer transactions, or the deployment and execution of contracts) also need to pay the corresponding fees (no free lunch in the world right!).
Ethereum uses the Gas mechanism for billing. Gas can also be considered a unit of work. The more complex the smart contract (the number and type of calculation steps, the memory used, etc.), the more Gas is needed to complete the operation.
The number of Gas contracts required for a particular contract to run is fixed and is determined by the complexity of the contract.
The Gas price is stipulated by the person who runs the contract when submitting the contract request to determine the price he is willing to pay for the transaction: Gas price (measured in dollars) * Gas ​​quantity.
The purpose of Gas is to limit the amount of work required to execute the transaction while paying for the execution. When the EVM executes the transaction, Gas will be gradually consumed according to specific rules. No matter where it is performed, an exception will be triggered once Gas is exhausted. All state changes made by the current call frame will be rolled back. If there is Gas remaining after the execution, these Gas will be returned to the sending account.
Without this restriction, someone would write a contract that could not be stopped (such as an endless loop) to block the network.
So in fact (to chain up the previous content), we need an external account with an Ethernet balance to initiate a transaction (regular transaction or deployment, running a contract), and the miners will charge the corresponding workload when they run.
Ethereum Networks
Select Ethernet Test Network Testnet
In the test network, we can easily obtain free Ethereum, the disadvantage is that it takes a long time to initialize the node.
Use private chain
Create your own Ethereum private test network, often referred to as a private chain, and we can use it as a test environment to develop, debug, and test smart contracts.
It's easy to create a test network of your own with Geth mentioned above. How much digging for etheric coins would also eliminate the need to synchronize the entire blockchain data of the official network.
Using Developer Network (Mode)
Compared to the private chain, under the developer network (mode), a developer account with a large amount of balance is automatically allocated for us to use.
Use a simulated environment
Another way to create a test network is to use testrpc, which is an Ethereum environment that uses memory simulation locally, making it easier and faster to develop and debug. And testrpc can help us create 10 test accounts with funds at startup.
When developing a contract, you can test in testrpc and deploy it to the Geth node.
Update: testrpc is now incorporated into the Truffle development framework and is now known as the Ganache CLI.
Dapp: Decentralized Applications
The Ethereum community refers to applications based on smart contracts as decentralized applications. If we understand the blockchain as a database that can't be tampered with, and smart contracts are understood as programs that deal with databases, it's easy to understand Dapp. A Dapp not only has smart contracts, but also needs a friendly user interface and other things.
Truffle
Truffle is Dapp development framework, he can help us deal with a lot of irrelevant little things, so that we can quickly begin to write code - compile - deploy - test - package DApp this process.
newbie
Activity: 52
Merit: 0
April 05, 2018, 10:37:37 AM
#2
thanck
jr. member
Activity: 98
Merit: 1
March 27, 2018, 12:38:39 AM
#1
 the basics of Ethereum that you will need to understand from a development standpoint, in order to produce contracts and decentralized applications. For a general introduction to Ethereum, see the white paper, and for a full technical spec see the yellow papers, although those are not prerequisites for this page; that is to say, this page is meant as an alternative introduction to Ethereum specifically targeted towards application developers.

There are two types of accounts:

1. Externally owned account (EOAs): an account controlled by a private key, and if you own the private key associated with the EOA you have the ability to send ether and messages from it.
2. Contract: an account that has its own code, and is controlled by code.

By default, the Ethereum execution environment is lifeless; nothing happens and the state of every account remains the same. However, any user can trigger an action by sending a transaction from an externally owned account, setting Ethereum's wheels in motion. If the destination of the transaction is another EOA, then the transaction may transfer some ether but otherwise does nothing.

However, if the destination is a contract, then the contract in turn activates, and automatically runs its code.

 Contracts generally serve four purposes:

  1. Maintain a data store representing something which is useful to either other contracts or to the outside world; one example of this is a contract that simulates a currency, and another is a contract that records membership in a particular organization.

  2. Serve as a sort of externally owned account with a more complicated access policy; this is called a "forwarding contract" and typically involves simply resending incoming messages to some desired destination only if certain conditions are met; for example, one can have a forwarding contract that waits until two out of a given three private keys have confirmed a particular message before resending it (ie. multisig). More complex forwarding contracts have different conditions based on the nature of the message sent; the simplest use case for this functionality is a withdrawal limit that is overrideable via some more complicated access procedure.

  3. Manage an ongoing contract or relationship between multiple users. Examples of this include a financial contract, an escrow with some particular set of mediators, or some kind of insurance. One can also have an open contract that one party leaves open for any other party to engage with at any time; one example of this is a contract that automatically pays a bounty to whoever submits a valid solution to some mathematical problem, or proves that it is providing some computational resource.

  4. Provide functions to other contracts; essentially serving as a software library.

The betting contract itself needs to fetch data about the San Francisco weather from some contract, and it also needs to talk to the GavCoin contract when it wants to actually send the GavCoin to either Alice or Bob (or, more precisely, Alice or Bob's forwarding contract).

Computation in the EVM is done using a stack-based bytecode language that is like a cross between Bitcoin Script, traditional assembly and Lisp (the Lisp part being due to the recursive message-sending functionality). A program in EVM is a sequence of opcodes

You do not need any special source file or library to use the eth object; however, your Đapp will only work when opened in an Ethereum client, not a regular web browser. For an example of the Javascript API being used in practice, see the source code of this webpage. (http://gavwood.com/gavcoin.html)

white paper : https://github.com/ethereum/wiki/wiki/White-Paper
yellow paper : http://gavwood.com/Paper.pdf
Jump to: