[Ethereum] Problem with truffle console : Cannot read property ‘call’ of undefined

contract-developmentsoliditytestrpctruffle

I have a problem when executing the code

HelloWorld.deployed().balance.call().then(console.log)

This error introduced: Cannot read property 'call' of undefined
This problem is similar to this thread but it does not help on my case.

enter image description here
Thanks for your help!

My code is from this turorial

contract HelloWorld {
  address public owner;
  mapping (address => uint) balances;
  function HelloWorld() {
    owner = msg.sender;
    balances[owner] = 1000;
  }
  function transfer(address _to, uint _value) returns (bool success) {
    if (balances[msg.sender] < _value) {
      return false;
    }
    balances[msg.sender] -= _value;
    balances[_to] += _value;
    return true;
  }
  function getBalance(address _user) constant returns(uint _balance) {
    return balances[_user];
  }
}

Best Answer

You don't have a method called "balance" but "getBalance" with an address argument "_user", so you need to call it this way:

HelloWorld.deployed().getBalance.call('YOUR_ADDRESS')
Related Topic