Ether Units
一个整数的后面可以跟一个单位,ether
,finney
,szabo
或者wei
。
他们的单位换算如下:
1 ether = 1000 finney
1 ether = 1000000 szabo 1
ether = 10 ** 18 wei
Time Units
时间的单位有seconds
, minutes
, hours
, days
, weeks
和 years
。换算如下:
1 == 1 seconds
1 minutes == 60 seconds
1 hours == 60 minutes
1 days == 24 hours
1 weeks == 7 days
1 years == 365 days
特殊的变量和函数和函数
有一些特殊的变量和函数存在于全局的命名空间以提供区块相关信息。
区块和交易属性
block.blockhash(uint blockNumber) returns (bytes32):
某个区块的区块链hash值block.coinbase (address):
当前区块的挖矿地址block.difficulty (uint):
当前区块的难度block.gaslimit (uint):
当前区块的gaslimitblock.number (uint):
当前区块编号block.timestamp (uint):
当前区块时间戳msg.data (bytes):
参数msg.gas (uint):
剩余的gasmsg.sender (address):
当前发送消息的地址msg.sig (bytes4):
方法IDmsg.value (uint):
伴随消息附带的以太币数量now (uint):
时间戳,等价于block.timestamp (uint)
tx.gasprice (uint):
交易的gas单价tx.origin (address):
交易发送地址错误处理
assert(bool condition):不满足条件,将抛出异常
- require(bool condition):不满足条件,将抛出异常
- revert() 抛出异常
在Solidity 0.4.10版本之前,使用throw来处理异常。如下所示:
contract HasAnOwner {
address owner;
function useSuperPowers(){
if (msg.sender != owner) {
throw;
}
}
}
在Solidity 0.4.10
版本之后,我们通常如下使用:
- if(msg.sender != owner) { revert(); }
- assert(msg.sender == owner);
- require(msg.sender == owner);