[Solidity] How to get the specific contract balance?

This section explains how to get the specific contract balance in Solidity.

Syntax

To get the specific contract balance in Solidity, do the following.

contract address (address type).balance

Sample Code

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract Test {

    function getContractBalance(address _address) public view returns(uint){
        // get contract balance
        return _address.balance;
    }

}

In addition to the balance acquisition (balance), the address type has other methods such as money transfer (transfer, send). When it comes to money operations, keep in mind the address type.

タイトルとURLをコピーしました