This question already has an answer here:

I am trying to run the following contract in truffle, which is pretty much the same HelloWorld but I kept the name MetaCoin from the truffle example. I have read this, this, and this posts related to this problem. Those fixes do not work in my case.

I am using Truffle v3.2.1 and testrpc client

    contract MetaCoin {
        uint public balance;

        function MetaCoin(){
            balance = 1000;

I compile, migrate and run console, and check it's been deployed:

    truffle(development)> MetaCoin.deployed();

And the output seems correct so far...

    TruffleContract {
       { [Function: TruffleContract]
  { setProvider: [Function: setProvider],
    new: [Function: new],
    at: [Function: at],
    deployed: [Function: deployed],
    defaults: [Function: defaults],
    hasNetwork: [Function: hasNetwork],
    isDeployed: [Function: isDeployed],
    detectNetwork: [Function: detectNetwork],
    setNetwork: [Function: setNetwork],
    resetAddress: [Function: resetAddress],
    link: [Function: link],
    clone: [Function: clone],
    addProp: [Function: addProp],
    toJSON: [Function: toJSON] },
  { contract_name: [Object],
    abi: [Object],
    network: [Function: network],
    networks: [Function: networks],
    address: [Object],
    links: [Function: links],
    events: [Function: events],
    binary: [Function: binary],
    unlinked_binary: [Object],
    schema_version: [Function: schema_version],
    updated_at: [Function: updated_at] },
 _property_values: {},
  { contract_name: 'MetaCoin',
    default_network: undefined,
    abi: [Object],
    unlinked_binary: '0x6060604052346000575b6103e86000555b5b60708061001f6000396000f300606060405263ffffffff60e060020a600035041663b69ef8a881146022575b6000565b34600057602c603e565b60408051918252519081900360200190f35b600054815600a165627a7a7230582041830854cedee45f2bd4eeaf84234adc0711a5415d238ee5c39b677b533974c30029',
    networks: [Object],
    schema_version: '0.0.5',
    updated_at: 1491813299298 },
 setProvider: [Function: bound setProvider],
 new: [Function: bound new],
 at: [Function: bound at],
 deployed: [Function: bound deployed],
 defaults: [Function: bound defaults],
 hasNetwork: [Function: bound hasNetwork],
 isDeployed: [Function: bound isDeployed],
 detectNetwork: [Function: bound detectNetwork],
 setNetwork: [Function: bound setNetwork],
 resetAddress: [Function: bound resetAddress],
 link: [Function: bound link],
 clone: [Function: bound clone],
 addProp: [Function: bound addProp],
 toJSON: [Function: bound toJSON],
  Web3 {
    _requestManager: [Object],
    currentProvider: [Object],
    eth: [Object],
    db: [Object],
    shh: [Object],
    net: [Object],
    personal: [Object],
    bzz: [Object],
    settings: [Object],
    version: [Object],
    providers: [Object],
    _extend: [Object] },
  { from: '0x3134fbda1c6ff76deb6c336b8460794ec842d2ae',
    gas: 4712388,
    gasPrice: 100000000000 },
 currentProvider: HttpProvider { host: 'http://localhost:8545', timeout: 0 },
 network_id: '1491808773134' },
       [ { constant: true,
   inputs: [],
   name: 'balance',
   outputs: [Object],
   payable: false,
   type: 'function' },
 { inputs: [], payable: false, type: 'constructor' } ],
      Contract {
  Eth {
    _requestManager: [Object],
    getBalance: [Object],
    getStorageAt: [Object],
    getCode: [Object],
    getBlock: [Object],
    getUncle: [Object],
    getCompilers: [Object],
    getBlockTransactionCount: [Object],
    getBlockUncleCount: [Object],
    getTransaction: [Object],
    getTransactionFromBlock: [Object],
    getTransactionReceipt: [Object],
    getTransactionCount: [Object],
    call: [Object],
    estimateGas: [Object],
    sendRawTransaction: [Object],
    signTransaction: [Object],
    sendTransaction: [Object],
    sign: [Object],
    compile: [Object],
    submitWork: [Object],
    getWork: [Object],
    coinbase: [Getter],
    getCoinbase: [Object],
    mining: [Getter],
    getMining: [Object],
    hashrate: [Getter],
    getHashrate: [Object],
    syncing: [Getter],
    getSyncing: [Object],
    gasPrice: [Getter],
    getGasPrice: [Object],
    accounts: [Getter],
    getAccounts: [Object],
    blockNumber: [Getter],
    getBlockNumber: [Object],
    protocolVersion: [Getter],
    getProtocolVersion: [Object],
    iban: [Object],
    sendIBANTransaction: [Function: bound transfer] },
 transactionHash: null,
 address: '0xdfefe34eb214332f4188c5582ddba2c1ea5cd623',
 abi: [ [Object], [Object] ],
  { [Function: bound ]
    request: [Function: bound ],
    call: [Function: bound ],
    sendTransaction: [Function: bound ],
    estimateGas: [Function: bound ],
    getData: [Function: bound ],
    '': [Circular] },
 allEvents: [Function: bound ] },
     { [Function]
 call: [Function],
 sendTransaction: [Function],
 request: [Function: bound ],
 estimateGas: [Function] },
      sendTransaction: [Function],
      send: [Function],
      allEvents: [Function: bound ],
     address: '0xdfefe34eb214332f4188c5582ddba2c1ea5cd623',
     transactionHash: null }

And now I try to check the balance in different ways:

    truffle(development)> meta = MetaCoin.deployed()
    truffle(development)> meta.balance.call()
    truffle(development)> MetaCoin.deployed().balance.call()
    truffle(development)> meta.balance.call().then(console.log)

and this is the error I get!

    TypeError: Cannot read property 'call' of undefined
        at evalmachine.<anonymous>:1:28
        at ContextifyScript.Script.runInContext (vm.js:32:29)
        at Object.runInContext (vm.js:87:6)
        at TruffleInterpreter.interpret (C:\Users\310267627\AppData\Roaming \npm\node_modules\truffle\lib\repl.js:136:17)
        at bound (domain.js:280:14)
        at REPLServer.runBound [as eval] (domain.js:293:12)
        at REPLServer.onLine (repl.js:536:10)
        at emitOne (events.js:96:13)
        at REPLServer.emit (events.js:191:7)
        at REPLServer.Interface._onLine (readline.js:241:10)

Any ideas?!

marked as duplicate by Badr Bellaj, Tjaden Hess, niksmac, Thomas Jay Rush, Joris Bontje Apr 22 '17 at 12:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Truffle 3.x?

Try waiting for returned promises ...

truffle(development)> var meta;
truffle(development)> var balance;
truffle(development)> MetaCoin.deployed().then(function(instance) { meta = instance; });
truffle(development)> meta.balance().then(function(bal) { balance = bal; });

truffle(development)> balance;
[big num ... ]
truffle(development)> balance.toString(10);
human readable ...

Not the answer you're looking for? Browse other questions tagged or ask your own question.