涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  428 随笔 :: 0 文章 :: 19 评论 :: 22万 阅读

单位和全局变量

Ether Units: wei, finney, szabo, ether

Time Units1 == 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


####数字与加密函数
```bash
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   北京涛子  阅读(164)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示