参考- http://solidity.readthedocs.io/en/develop/assembly.html
目标-返回合同地址的函数的示例。
密码-
pragma solidity ^0.4.18;
contract d4{
function showAddress() view public returns (address addr_v) {
assembly {
addr_v := mload(0x30)
}
}
}这个编译好了,但只返回0。
我使用这个链接作为操作码- https://github.com/ethereum/pyethereum/blob/develop/ethereum/opcodes.py。
是否有使用操作码确定合同地址的代码示例?
发布于 2018-03-11 09:59:20
按照https://solidity.readthedocs.io/en/v0.4.20/julia.html,this()应该可以工作。
(当然,没有程序集的return address(this)也是如此,在不知道地址的情况下调用函数是不可能的,所以我不清楚您的需求是什么。)
发布于 2019-11-03 21:27:11
function showAddress() view public returns (address addr_v) {
assembly {
addr_v := address()
}
}详情请参见文档。
https://ethereum.stackexchange.com/questions/42382
复制相似问题