1.状态变量
pragma solidity >=0.4.0 <0.6.0;
contract SimpleStorage {
uint storedData;
}
2.函数
pragma solidity >=0.4.0 <0.6.0;
contract SimpleAuction {
function bid () public payable{
}
}
3.函数修饰器
pragma solidity >=0.4.22 <0.6.0;
contract Purchase{
address public seller;
modifier onlySeller() {
require{
masg.sender == seller,
"Only seller can this."
};
_;
}
}
4.事件
pragma solidity >=0.4.0 <0.6.0;
contract SimpleAuction {
event HighestBidIncreased (address bidder, uint amount) ;
function bid () public payable{
emit HighestBidIncreased (msg.sender, msg.value) ;
}
}
5.结构体
pragma solidity >=0.4.0 <0.6.0;
contract Ballot{
struct Voter{
uint weight;
bool voted;
address delegate;
uint vote;
}
}
6.枚举类型
pragma solidity >=0.4.0 <0.6.0;
contract Purchase{
enum State { Created, Locked, Inactive }
}