I am using this ERC223 compliant code to accept an ERC20 token as payment (provided by @aviral agrawal). Why does the compiler keep asking me to declare the balances function? I thought it was an built-in function? It did this for the balanceOf and safeSub functions as well.

pragma solidity ^0.4.2;

contract getLaundri{

function balanceOf( address who ) constant returns (uint balances) {
  return balances[who];

function transferToContract(address _to, uint _value, bytes _data) private returns (bool success) {

require(balanceOf(msg.sender) >= _value);
balances[msg.sender] = safeSub(balanceOf(msg.sender), _value);
balances[_to] = safeAdd(balanceOf(_to), _value);
ContractReceiver reciever = ContractReceiver(_to);
reciever.tokenFallback(msg.sender, _value, _data);
Transfer(msg.sender, _to, _value, _data);
StateChanged(true,"Transfer to contract successful");
return true;



This is the error message:

 Undeclared identifier.
balances[msg.sender] = safeSub(balanceOf(msg.sender), _value);

You never declared the property balances on your contract. It's not built-in, it's a implementation detail of most token contracts. If you look at some others, you'll see something like mapping balances(address => uint256) declared within the scope of the contract itself (not one of its functions).


ERC20 and ERC223 are standards that provide a skeleton of what functionalities, variables and event your smart contract must have in order for it to be a standard token. These functions and variables are not in built and must be declared.

Declare the balances as a mapping as mentioned by @DeviateFish. Also include all the functionalities of ERC223 to make it a standard token

Thank you for the mention. It means a lot to me.

P.S. Always use the latest version of solidity. Each release brings a whole lot of functionalities(As of writing 0.4.14)

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.