地址相关(Address Related)

优质
小牛编辑
119浏览
2023-12-01

<address>.balance (uint256)

Address的余额,以wei为单位。

<address>.transfer(uint256 amount)

发送给定数量的ether,以wei为单位,到某个地址。失败时抛出异常。

<address>.send(uint256 amount) returns (bool):

发送给定数量的ether,以wei为单位,到某个地址。失败时返回false

<address>.call(...) returns (bool)

发起底层的call调用。失败时返回false

<address>.callcode(...) returns (bool)

发起底层的callcode调用,失败时返回false

<address>.delegatecall(...) returns (bool)

发起底层的delegatecall调用,失败时返回false

更多信息参加Address章节1

使用send方法需要注意,调用栈深不能超过1024,或gas不足,都将导致发送失败。使用为了保证你的ether安全,要始终检查返回结果。当用户取款时,使用transfer或使用最佳实践的模式2

合约相关

this(当前合约的类型)

当前合约的类型,可以显式的转换为Address

selfdestruct(address recipt):

销毁当前合约,并把它所有资金发送到给定的地址。

另外,当前合约里的所有函数均可支持调用,包括当前函数本身。

参考资料


  1. 更新关于地址的call,callcode,delegateCall的介绍。http://me.tryblockchain.org/Solidity-call-callcode-delegatecall.html ↩

  2. http://solidity.readthedocs.io/en/develop/common-patterns.html#withdrawal-from-contracts ↩