Back to homepage

How to get a smart contract balance


In order to get the balance of a smart contract, you first need to obtain the contract address. For that, you can use the this keyword which refers to the contract itself.

Once you have the contract address, you can call the balance property, which will return the contract balance.

You can do this in a single line of code 👇


If what you want is to obtain the balance of a diferent contract, you can use a function like this:

function getContractBalance(address ContractAddress) public view returns(uint){
    return ContractAddress.balance;

Hope this quick tip was helpful 🤙


If you enjoyed this article consider sharing it on social media or buying me a coffee ✌️

Buy Me A Coffee