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