每当我尝试执行使用address(this).balance
的函数时,我都会得到一个invalid opcode
错误。它使用0.6.0进行精细编译。
使用松露调试,我得到以下错误:
Transaction halted with a RUNTIME ERROR.
There was no revert message. This may be due to an in intentional halting expression, such as assert(), revert(), or require(), or could be due to an unintentional exception such as out-of-gas exceptions.
Please inspect your transaction parameters and contract code to determine the meaning of this error.
我检查了文档,但是使用address(this).balance
并没有改变。我是不是遗漏了什么?
编辑:我刚刚在混合中测试了这段代码,它也抛出了:
pragma solidity 0.6.0;
contract A {
uint public total;
receive() external payable {
total = address(this).balance;
}
}
发布于 2019-12-29 10:53:37
我通过在我的松露配置文件中显式定义EVM版本来修复它。这仍然很奇怪,因为Remix也支持这一点(如附件中所示),但仍然失败。
compilers: {
solc: {
version: "0.6.0",
settings: {
optimizer: {
enabled: true
},
evmVersion: "petersburg"
}
}
}
编辑:我为这里团队创建了一个问题。
发布于 2019-12-29 10:35:25
在总结上面的评论时,编译器版本0.5.13的更改日志提到了一个相关的修复:
代码生成器:如果使用伊斯坦布尔EVM,则为
address(this).balance
使用SELFBALANCE
操作码。
所以我冒昧地猜测你的问题:
我想知道(并担心)在已经编译和部署的使用address(this).balance
的合同中会发生什么.
https://ethereum.stackexchange.com/questions/78597
复制相似问题