solidity语言7

it2022-05-05  149

solidity语言7

单位和全局变量

Ether Units: wei, finney, szabo, ether Time Units: 1 == 1 seconds 1 minutes == 60 seconds 1 hours == 60 minutes 1 days == 24 hours 1 weeks == 7 days 1 years == 365 days function f(uint start, uint daysAfter) public { if (now >= start + daysAfter * 1 days) { // ... } }

专用变量和函数

block.blockhash(uint blockNumber) returns (bytes32): hash of the given block - only works for 256 most recent blocks excluding current block.coinbase (address): current block miner’s address block.difficulty (uint): current block difficulty block.gaslimit (uint): current block gaslimit block.number (uint): current block number block.timestamp (uint): current block timestamp as seconds since unix epoch msg.data (bytes): complete calldata msg.gas (uint): remaining gas msg.sender (address): sender of the message (current call) msg.sig (bytes4): first four bytes of the calldata (i.e. function identifier) msg.value (uint): number of wei sent with the message now (uint): current block timestamp (alias for block.timestamp) tx.gasprice (uint): gas price of the transaction tx.origin (address): sender of the transaction (full call chain)

错误处理

assert(bool condition): throws if the condition is not met - to be used for internal errors. require(bool condition): throws if the condition is not met - to be used for errors in inputs or external components. revert(): abort execution and revert state changes ```

数字与加密函数

addmod(uint x, uint y, uint k) returns (uint): compute (x + y) % k where the addition is performed with arbitrary precision and does not wrap around at 2**256. mulmod(uint x, uint y, uint k) returns (uint): compute (x * y) % k where the multiplica-tion is performed with arbitrary precision and does not wrap around at 2**256. keccak256(...) returns (bytes32): compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments sha256(...) returns (bytes32): compute the SHA-256 hash of the (tightly packed) arguments sha3(...) returns (bytes32): alias to keccak256 ripemd160(...) returns (bytes20): compute RIPEMD-160 hash of the (tightly packed) arguments ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address): recover the address associated with the public key from elliptic curve signature or return zero on error (example usage)

地址相关

<address>.balance (uint256): balance of the Address in Wei <address>.transfer(uint256 amount): send given amount of Wei to Address, throws on failure <address>.send(uint256 amount) returns (bool): send given amount of Wei to Address, returns false on failure <address>.call(...) returns (bool): issue low-level CALL, returns false on failure <address>.callcode(...) returns (bool): issue low-level CALLCODE, returns false on failure <address>.delegatecall(...) returns (bool): issue low-level DELEGATECALL, returns false on failure

合约相关

this (current contract’s type): the current contract, explicitly convertible to Address selfdestruct(address recipient): destroy the current contract, sending its funds to the given Address suicide(address recipient): alias to selfdestruct Furthermore, all functions of the current contract are callable directly including the current function. posted on 2018-02-28 11:55 北京涛子 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/liujitao79/p/8482857.html


最新回复(0)