Chapter 4 Introduction to Ethereum Smart Contract Solidity

Solidity is a contract-oriented, high-level programming language created to implement smart contracts, designed to run on the Ethereum Virtual Machine.

This chapter briefly introduces the basic information of the contract, the composition of the contract, and the grammar. I personally recommend reading more official documents for better results. Subsequent chapters will develop ERC20 token contract cases for better learning of smart contracts. to develop

Official website documentation: https://docs.soliditylang.org/en/v0.8.12/

Chinese documentation: https://learnblockchain.cn/docs/solidity

1. Introduction to the first contract

Let's take a look at the simplest contract code for accessing integer data

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

The first line indicates that the source code is licensed under the GPL 3.0 copyright. It is very important to add a machine-readable license description to the code. It is required by default when releasing the source code, just copy it directly.

The second line is to tell the compiler that the applicable solidity version of the source code is >=0.4.16 <0.9.0. If it is defined like this: pragma solidity ^0.5.2, the source file will neither allow versions lower than 0.5.2 The compiler compiles, and does not allow higher than (contains &#x

Guess you like

Origin blog.csdn.net/u010857052/article/details/123620280