What is the difference between this.balance VS address(this).balance in solidity contracts?


this represents a "contract instance" object for the current contract. The balance function is part of the "address" object. You used to be able to do this.balance because solidity would allow implicit access to the address functions through the contract instance object.

However, as of Solidity 0.4.22, the recommended practice is to use address(this).balance which explicitly converts this (the current contract instance) to an address object.

In Solidity 0.5.0, this.balance will be explicitly forbidden, and you will be required to explicitly convert to the address object before you can access it's functions.

You may find code using the older syntax due to historical practices, but you should use the modern syntax for any new contracts that you write.


I have to use this, but im on the Energi chain

Solidity 0.7.5

return (payable(address(this))).balance;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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