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

0 votes

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.

Sep 25, 2018 in Blockchain by digger
• 26,740 points
921 views

2 answers to this question.

0 votes

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
    );
}
answered Sep 25, 2018 by slayer
• 29,350 points
0 votes

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
  );
}
answered Oct 3, 2018 by Rustom

Related Questions In Blockchain

0 votes
1 answer

How do I withdraw the balance from a contract on Ethereum test blockchain?

Your need to improvise your code a ...READ MORE

answered Aug 3, 2018 in Blockchain by Perry
• 17,100 points
2,451 views
+1 vote
3 answers

What is the pattern for handling throw on a Solidity contract in tests

In my opinion the cleanest way is: it("should ...READ MORE

answered Sep 25, 2018 in Blockchain by Lupin
1,544 views
0 votes
1 answer

Solidity mocha : address is not a contract error

Try the following: // Initialize contract variable with ...READ MORE

answered Oct 1, 2018 in Blockchain by digger
• 26,740 points
803 views
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,690 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
43,937 views
0 votes
1 answer

Getting the length of public array variable (getter)

The calling contract will need the ABI ...READ MORE

answered Sep 24, 2018 in Blockchain by digger
• 26,740 points
1,185 views
0 votes
1 answer

How to get value from solidity contract using java?

web3j caters for this very use case. It ...READ MORE

answered Sep 28, 2018 in Blockchain by slayer
• 29,350 points
1,743 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP