# How to return balance of smart contract for particular address in solidity?

I want to create a function which will accept address as argument and return balance of smart contract here is what i

``````function get_balance(address _add)
{
return balance;

}
``````

But it giving me following

`````` Different number of arguments in return statement than in returns declaration.
return balance;
``````

Please let me where i am wrong or is there any other way to return balance

Here is full code of contract

``````pragma solidity ^0.4.6;
contract RUBY {
string public standard = 'RUBY 1.0';
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
uint256 public balance;
mapping (address => uint256) public balanceOf;
function RUBY() {
balanceOf[msg.sender] = 10000;
totalSupply = 10000;
name = 'RUBY';
symbol = 'RUBY';
decimals = 8;
owner=msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_;
}
}

function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw;
if (balanceOf[msg.sender] < _value) throw;
if (balanceOf[_to] + _value < balanceOf[_to]) throw;
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
Transfer(msg.sender, _to, _value);
}
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
return true;
}
}
if (_to == 0x0) throw;
if (balanceOf[_from] < _value) throw;
if (balanceOf[_to] + _value < balanceOf[_to]) throw;
if (_value > allowance[_from][msg.sender]) throw;
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
allowance[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
}
}
``````

In your function definition, you're missing the returns param type:

``````function get_balance(address _add) returns(<balance_var_type>)
{
return balance;

}
``````

Try this way, it should work, anyway post the whole code of your contract. However, in that way you get the balance of your custom token, not the ETH balance of the wallet. If you need the ETH balance you have to do something like this:

``````function getEthBalance(address _addr) constant returns(uint) {
}
``````

N.B: the balance result is in Wei not in ETH. Hope it helps.

Edit:

With the function get_balance() you can return the balance of RUBY token of an account. • I have edit question and added full code of contract the function i have added is not accessible can you please check – Anil Baweja Jul 18 '17 at 15:32
• Which function? getBalance()? – Paolo Guerra Jul 18 '17 at 17:02
• I've tried your code and the getBalance() returns correctly the amount of ETH – Paolo Guerra Jul 18 '17 at 17:04
• but i need the balance of RUBY(contract i have created) – Anil Baweja Jul 18 '17 at 20:08
• So you're function is fine: function get_balance(address _add) returns(uint256) { balance = balanceOf[_add]; return balance; } – Paolo Guerra Jul 18 '17 at 21:39