3

Warning: Using contract member "balance" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).balance" instead.

I am getting this warning in Solidity using the Remix editor.

This is the code chunk:

function getSummary() public view returns(
    uint, uint, uint, uint, address
){
    return (
        minimumContribution,
        this.balance, // This is the warning line.
        requests.length,
        approversCount,
        manager
    );
}

I tried following what the warning suggests:

function getSummary() public view returns(
    uint, uint, uint, uint, address
){
    return (
        minimumContribution,
        address(contract).balance,
        requests.length,
        approversCount,
        manager
    );
}

But that does not work.

Matt
  • 33,328
  • 25
  • 83
  • 97

2 Answers2

5

balance is an attribute of the address type, not from a contract. Change it to address(this).balance.

function getSummary() public view returns(
    uint, uint, uint, uint, address
){
    return (
        minimumContribution,
        address(this).balance,
        requests.length,
        approversCount,
        manager
    );
}
Adam Kipnis
  • 10,175
  • 10
  • 35
  • 48
2

Alternatively you could assign this to a local variable of type address...

address contractAddress = this;

function getSummary() public view returns(
    uint, uint, uint, uint, address
){
  return (
    minimumContribution,
    contractAddress.balance,
    requests.length,
    approversCount,
    manager
  );
}
Benni Russell
  • 354
  • 2
  • 7