Search code examples
ethereumsolidityremixether

Warning: Using contract member "balance" inherited from the address type is deprecated. Solidity


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.


Solution

  • 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
        );
    }