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
• 27,620 points
70 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,040 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
• 16,450 points
44 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
89 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
• 27,620 points
32 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
81 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
• 27,620 points
1,772 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
• 27,620 points
23 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,040 points
138 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.