30

How do I get the balance of a contract with solidity? I know geth has web3.eth.getBalance(), but that's to get the contract balance after it has been deployed.

Is there a standard way of doing this, or do I have to have a separate var that uint256 that keeps track of the total balance?

37

You can do this by calling address.balance. To get the contract's balance, just do this.balance. Read the docs.

Update: As of Solidity ^0.4.24, you need to do:

address(this).balance

(Copied from answer by Paul Berg)

20

Small update from my side:

enter image description here

You want to use the following, address(this).balance;

10

As of Solidity ^0.4.24, you need to do:

address(this).balance

Find an example here.

Your Answer

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