警告:不赞成使用从地址类型继承的合同成员“余额”。团结

时间:2018-07-17 02:21:02

标签: ethereum solidity remix ether

  

警告:不赞成使用从地址类型继承的合同成员“余额”。将合同转换为“地址”类型以访问成员,例如,改为使用“ 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
    );
}

但这不起作用。

2 个答案:

答案 0 :(得分:3)

balanceaddress类型的属性,而不是来自合同。将其更改为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
  );
}