Solidity Official Document Learning Note (2)

Source: Internet
Author: User
Tags modifier modifiers visibility
Overview of the basic elements of smart contracts

Contracts are similar to classes in object-oriented languages.

Support inheritance.

Each contract can contain a state variable (Variables), a function (Functions), a function modifier (functions Modifiers), an event (events), a struct type (Structs Types), and an enumeration type (enum Types). status variable (state Variables) variable value is permanently stored in the contract's storage space

Simple Store Example

contract simplestorage{

    uint Valuestore;//state variable

}

See the type (Types) section for details on the visibility of all supported types and variables (Visibility and accessors).

function (Functions)An executable unit in a smart contract.

Contract simplemath{
    //simple add function,try a divide action?
    function add (uint x, uint y) returns (UINT Z) {
        z = x + y;
    }
}
The example above shows a simple addition function.
function calls can be set to internal (Internal) and external (External). At the same time for different levels of visibility and access control for other contracts (Visibility and accessors). For details, see the contents of the function in the following type.
functions modifier (function Modifiers)function modifiers are used to enhance semantics.

Event (events)Events are a convenient interface provided by the Ethereum virtual machine (EVM) log infrastructure. Used to get the event that is currently occurring.

Contract Simpleauction {
    Event anewhigherbid (address bidder, uint amount);
    
    function  Bid (UINT Bidvalue) external {
        anewhigherbid (Msg.sender, Msg.value);
    }
}
about how events are declared and used.
struct type (Structs Types)
A custom type that combines several variables to form together.
Contract company {
    //user defined ' Employee ' struct type
    //group with serveral variables
    struct EMPLOYEE{
  string name;
        UINT Age;
        UINT salary;
    }
    
    User defined ' manager ' struct type
    //group with serveral variables
    struct manager{
        employee employ;
        string title;
    }
}

enum type (enum)For a particular custom type, all values of the type can be enumerated in the case.
Contract Home {
    enum Switch{on,off}
}

Appendix Learning Reference Links: http://wiki.jikexueyuan.com/project/solidity-zh/introduction-smart-contracts.html/http www.tryblockchain.org/Smart contract elements. html


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.