I'm just learning about coding in general, and fighting my way through an Ethereum course.

I've seen the answers about the "contract member balance is deprecated" issue, but I'm just trying to use it in the following:
function GetMyContractBalance() public constant returns (uint) {
return this.balance;

I added:

address myAddress = this;

but how do I construct it just using that return function? I've tried:

require (return (this).balance);
require return (this).balance;
return (this).balance;

aaaannnnddd - I'm pretty much out of ideas.

Thanks in advance.

1 Answer 1


I'm not 100% sure I understand the question, but possibly something here will help.

this.balance was okay when contracts were directly convertible to addresses. Since <address>.balance is the key, things like 0x1234...balance and msg.sender.balance work as expected. this.balance was working without issue, but more recent compilers want an explicit conversion from type contract to type address.

So convert this (contract) to an address with address(this).

Then you can go address(this).balance.

As a one-liner:

return address(this).balance;

Hope it helps.

  • That was it!!! Thanks so much for the both the answer and the explanation - it makes complete sense.
    – therealex
    Commented May 23, 2018 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.