Solidity development Note

Version pragma: 1, version 0.4.24 above can be compiled; 2, higher than 0.5 is not compiled version; 3, the third version number can be changed, can be left out bug fixes used (e.g., 0.4.1 the compiler has a bug, can be repaired in 0.4.2, the existing contracts do not change the code).

Note: 1, single-line comment // 2, multi-line comments /*....*/ 3, natspec annotation, which is three slash (//) or the beginning of the block double asterisk (/ **. .. * /) writing, they should be used directly in the function declaration or statement.

Event: Ethernet virtual machines Square logging facilities convenient interface.

Structure: it may be several custom type variables packet (custom template complex variable).

It may be defined as state variables constant, constant. In this case, it must be an expression assignment during compilation. Assignment of expression is not allowed: 1, access to storage; 2, block chain data, such as now, this.balance, block.number; 3, intermediate data execution of the contract, such as msg.gas; 4, initiate calls to external contracts . Note: Not all types are supported constants, currently supported only value types and strings.

 

 

Fallback method

 

function () public payable {
}

 

The name is no  Fallback method. A contract can only be one. This method has no parameters, and no return value. If someone calls this contract, but can not find the specified method, it will be triggered.

 

Also, when the contract address simply receive Ether (such as the transfer of others to this contract addresses), this method will be called. Therefore, it must be labeled  payable . Otherwise, this agreement would not be able to receive Ether address by ordinary transactions.

 

It is noted that, if there are logical this method, make sure it is less than 2300 Gas consumption.

 

Guess you like

Origin www.cnblogs.com/zhangmingcheng/p/10510591.html