Smart contracts from entry to mastery: developing a "Hello World" with Solidity

Introduction: In the last chapter , we talked about the application scenarios of smart contracts. After understanding the current development of blockchain technology, the concept of smart contracts and their application scenarios, we will learn about the compilation of smart contracts in subsequent articles. language. Today, let's briefly talk about the language used to write smart contracts - Solidity language.

So, what is the Solidity language? In the previous articles, we have repeatedly mentioned Ethereum. Ethereum is a typical representative of blockchain 2.0. Solidity is the most popular language for writing smart contracts in Ethereum. Therefore, today we will introduce this as a smart contract. The most mainstream language in contract development.

Solidity is a high-level language for smart contracts running on the Ethereum Virtual Machine (EVM). Its syntax is similar to Javascript and it is an object-oriented language. But as a kind of decentralized contract that really means running on the network, it has various special features. We list some of them below, so that everyone can understand the features of Solidity language more intuitively.

1. In the Solidity language, the underlying structure of Ethereum is based on accounts rather than UTXOs, so it has a special type of Address for locating users, contracts and contract code (and the contract itself is also an account).

2. Solidity language has the feature of language embedded framework supporting payment. It provides a series of keywords such as payable, which can be directly paid at the language level, which is quick and easy to use.

3. Storage. The storage of the Solidity language uses the existing blockchain on the network. Each stage and state of the data can be permanently stored, so it is necessary to clarify whether the variable uses the memory or the blockchain.

4. Regarding the operating environment of Solidity, its operating environment is built on a decentralized network, emphasizing the way in which contracts or functions are executed. Because the original simple function call has become the code execution of a node in the network, which has the characteristics of distributed.

5. Finally, the Solidity language has a very special exception handling mechanism. Once any abnormality occurs in the process, all executions will be forced to withdraw. This mechanism effectively avoids the sudden data inconsistency in the intermediate state, thereby ensuring the atomicity of contract execution.

As the first demo program used in "The C Programme Language", Hello World may sound very high-end in the programming world, but it is actually very simple to get started:

pragma solidity ^0.4.0;
contract HelloWorld{
uint balance;
function update(uint amount) returns (address, uint){
balance += amount;
return (msg.sender, balance);
}
}

As shown above, by reading the new value entered by the parameter and accumulating it into the variable of the contract, the sender's address is returned, and the final accumulated value is returned.

Finally, here is a browser compiler - Remix.

The browser compiler Remix can be called the development artifact of the Solidity language. It is an online compiler that can be used without installation. Just open its website, you can use it online and see the effect. After opening, as shown in the following figure:
Smart contracts from entry to mastery: developing a "Hello World" with Solidity
Enter the above code and click the Create button to create a button in the browser that can call the function. Enter the input parameters next to the update button, click to execute the function call and print out the result returned by the function.
Smart contracts from entry to mastery: developing a "Hello World" with Solidity
(If an error occurs, you can wait for the browser resource to load, or force a refresh and try again.)

In addition to Remix, today we will introduce a domestic compiler: JIDE.

JIDE is a free development tool provided by the JUICE open service platform for writing smart contracts and DApps. JIDE integrates the JUICE underlying test chain, editor and Solidity runtime environment. Users can quickly write, compile, deploy, Run smart contracts.

Like Remix, JIDE is also an online compiler that can be used without installation. Just open its website, you can use it online and see the effect.http://www.juzix.net/

JIDE provides complete Chinese development documentation, which is very convenient for beginners. Smart contracts from entry to mastery: developing a "Hello World" with Solidity
For the full syntax of Solidity, stay tuned for a follow-up article.
Partial source: www.tryblockchain.org

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324656687&siteId=291194637