Basic smart contract lesson 1 (Introduction to smart contract)


1. What can you gain from this course?

After learning this tutorial, you will use solidity language to write some small smart contracts to achieve an entry level requirement for smart contracts. Through this tutorial, you can increase your interest in smart contract. In the future, you can go further on the road of smart contract through self-study or our advanced courses. That is to say, this course is a basic course. It is suitable for smart contract employees.

2. What is a smart contract?

Smart contract is not a common contract in reality, but a piece of program code that exists on the blockchain and can be triggered to execute. These codes implement certain predetermined rules and are “autonomous agents” existing in the execution environment of blockchain. If the smart contract is triggered, the code will execute. If it is not triggered, its state will always remain in a state, and the deployed smart contract will not be modified. The syntax of smart contract language is very similar to JS scripting language, so partners who have JS development experience will learn it quickly.

3. What can we do after learning smart contract?

We will be able to complete the development tasks as the underlying personnel of blockchain applications. Smart contracts are the core and key part of decentralized applications. In the abstract, the smart contract is the database and server of the application.

4. Introduction of programming tools.

We all know the truth that “to do well in advance, we must first sharpen the tools”. In reality, weaving requires a loom to complete weaving. Similarly, our smart contract learning also requires the use of programming tools. We will use Remix as the programming tool to explain the course. Remix is the loom in our hands. It depends on us programmers who use Remix.
The address is Can be developed directly in the browser, very convenient, as long as there is a Google Chrome Google browser can be developed.

Remix has several main commonly used panels, which are file panel, compiler, runner, and the most important part of the text editor.

File panel: we can create files, select files and manage files in this panel.
Compiler: we can compile the sol file. If the compilation fails, the contract will not be executed, and we can get the code.json as well as abi.json 。 We can run them on a public chain that supports sol.
Runner: the sol smart contract can be deployed on the ETH chain, and the contract method can be called.
Text editor: our code is written in this location. You will face this page most of the time.

5. My first smart contract app

The following smart contract is our first contract program, so we named it“ FirstContract.sol ”File name

pragma solidity ^0.6.0;

// first contract
contract FirstContract {
    // first method
    function firstMethod() public pure returns (string memory) {
        return 'I am first method !!!';

Many of the above code partners should not understand what the meaning, do not understand it does not matter, I will give you a line by line explanation.

pragma solidity ^0.6.0;

This line indicates that it is written in solidity version 0.6.0 and can run on versions between 0.6.0 and 0.7.0.

contract FirstContract {

This sentence defines a contract called firstcontract.

function firstMethod() public pure returns (string memory){

This line defines a method called firstmethod, which has a return value of type string.

return 'I am first method !!!';

The line is that this method will return “I am first method!”.

It seems that there may still be some partners who don’t understand, but we only teach so much about what is string. String is the meaning of string. String can be regarded as any ABCDE, and the punctuation marks are written in single quotation marks or double quotation marks. This is the most easy to understand string interpretation, friends, you can try to customize some strings to let him return.

6. Smart contract deployment

Friends should be in the current page!
Basic smart contract lesson 1 (Introduction to smart contract)

We click the solidness button to enter solidity.

Basic smart contract lesson 1 (Introduction to smart contract)
We go to the compiler panel and check the (2) (3) option, (2) auto compile, (3) auto optimize.
Basic smart contract lesson 1 (Introduction to smart contract)

The teacher created it here FirstContract.sol File, and then the file content is the code above. Next, we will deploy it to the ETH network.
Basic smart contract lesson 1 (Introduction to smart contract)
It is divided into four parts. Let’s make sure that the contract we want to publish is in the text editing panel. Then click the side icon of the operation to enter the operation panel, and then confirm that the contract in our (3) is the contract that we will deploy, and then click the deploy button to deploy.
Basic smart contract lesson 1 (Introduction to smart contract)
After successful deployment, these contents will be added to the (1) and (1) positions marked above. The location of 1 is the smart contract we deployed, which can be used to operate the smart contract. (2) The location of is the deployment. A green one in front of us indicates that we have successfully deployed. We click (1) to expand the panel. As shown in the figure below:
Basic smart contract lesson 1 (Introduction to smart contract)
After we click the first method button, we will display the return information in the following point, that is, the position of (2) will be returned, and (3) is the call information of this execution. Generally, after the execution fails, we will check the error through this line, but we will repeat here.

7. Homework of this period

You will deploy your smart contract according to the smart contract simulation in this section. Requirements: the contract name is confluxtask, the method name is creator DESC, and the return is “my creator is XXX!!!” XXX is your own micro signal.

Basic smart contract lesson 1 (Introduction to smart contract)

8. Conclusion

Thank you for reading this article. If you are interested in conflux, you can add my wechat (15832013094) or teacher long’s wechat (Ye)_ In 2013, we entered the seminary. All courses of conflux seminary will be free forever, and you may get some extra money. Join us to learn and progress together.