警告:不赞成使用从地址类型继承的合同成员“余额”。将合同转换为“地址”类型以访问成员,例如,改为使用“ address(contract).balance”。
我正在使用Remix编辑器在Solidity中收到此警告。
这是代码块:
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
this.balance, // This is the warning line.
requests.length,
approversCount,
manager
);
}
我尝试遵循警告提示:
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
address(contract).balance,
requests.length,
approversCount,
manager
);
}
但这不起作用。
答案 0 :(得分:3)
balance
是address
类型的属性,而不是来自合同。将其更改为address(this).balance
。
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
address(this).balance,
requests.length,
approversCount,
manager
);
}
答案 1 :(得分:0)
或者,您可以将this
分配给类型为address
的局部变量...
address contractAddress = this;
function getSummary() public view returns(
uint, uint, uint, uint, address
){
return (
minimumContribution,
contractAddress.balance,
requests.length,
approversCount,
manager
);
}