Index"Solidity" 1. The layout of a solidity source file "solidity" 2. Structure of the contract
"Solidity" 3. Type "solidity" 4. Unit and global variable "solidity" 5. Expression and control structure "solidity" 6. Contract
"Solidity" 7. Part "solidity" 8. Miscellaneous
2 structure of the contract
Solidity contracts are similar to classes in object-oriented languages. Each contract can contain state Variables, functions, Function modifiers, Events, Structs Types, and Enum Types declarations. In addition, contracts can be inherited from other contracts. State Variables
A state variable is a value that is permanently stored in the contract store.
pragma solidity ^0.4.0;
Contract Simplestorage {
uint Storeddata;//state variable
//...
}
See the "Type" section, "Visibility", and "get" on the type of state variable to get a possible selection of visibility. function Functions
A function is an executable unit in a code contract.
pragma solidity ^0.4.0;
Contract Simpleauction {function
bid () payable {//function
//...
}
}
Function calls can occur either internally or externally, with varying degrees of visibility on other contracts (visibility and getter). function modifiers function modifiers
function modifiers can be used to declaratively modify the semantics of a function (see the function modifiers in the contract section).
pragma solidity ^0.4.11;
Contract Purchase {address public
seller;
Modifier Onlyseller () {//Modifier
require (msg.sender = seller);
_;
}
function abort () Onlyseller {//Call modifier
//...
}
}
Events
Event is an easy interface with the EVM log tool.
pragma solidity ^0.4.0;
Contract Simpleauction {Event
highestbidincreased (address bidder, uint amount);//Events
function bid () payable {
// ...
Highestbidincreased (Msg.sender, Msg.value); Triggering event
}
}
See the events section of the contract for information about how events are declared and can be used within DAPP. Structure Type
Structs is a custom type that can group several variables (see the structure body in the type part).
pragma solidity ^0.4.0;
Contract ballot {
struct voter {//struct body
uint weight;
BOOL voted;
Address delegate;
UINT Vote
}
}
Enum Type
Enumeration can be used to create a custom type with a finite set of values (see enumerations in the Type section).
pragma solidity ^0.4.0;
Contract Purchase {
enum state {Created, Locked, Inactive}//enum
}