我正在编写两份合同。在"HoneyPotCollect.sol“合同中,我得到了'balance‘变量错误。平衡不是全球契约变量吗?请有人指点我如何改正错误。
//HoneyPot.sol
pragma solidity ^0.5.0;
contract HoneyPot {
mapping (address => uint) public balances;
constructor() payable public {
put();
}
function put() payable public {
balances[msg.sender] = msg.value; // msg.sender here is the address from the sender
}
function get() public {
(bool success,) = msg.sender.call.value(balances[msg.sender])("");
success = false;
//revert();
balances[msg.sender] = 0;
}
function() external {
revert();
}
}//HoneyPotCollect合同
pragma solidity ^0.5.0;
import './HoneyPot.sol';
contract HoneyPotCollect {
HoneyPot public honeypot;
constructor(address _honeypot) public {
honeypot = HoneyPot(_honeypot);
}
function kill () public {
selfdestruct(msg.sender);
}
function collect() payable public {
honeypot.put.value(msg.value)();
honeypot.get();
}
function () external payable {
if (honeypot.balance >= msg.value) {
honeypot.get();
}
}
}以下是我的错误信息:
$ solc HoneyPotCollect.sol HoneyPotCollect.sol:19:9: Error:成员"balance“在依赖于参数的HoneyPot中查找后未找到或不可见。使用“地址(蜜罐).balance”访问此地址成员。if (honeypot.balance >= msg.value) {^
发布于 2020-06-24 13:47:44
balance不是一个全局契约变量吗?
不是,但它是address类型的成员,所以请更改如下:
honeypot.balance对此:
address(honeypot).balance有关更多详细信息,请参阅正式文件。
https://ethereum.stackexchange.com/questions/84500
复制相似问题