5

I am running HelloWorld contract.

pragma solidity ^0.4.2;
contract HelloWorld {
    uint public balance;

    function Helloworld(){
        balance = 1000;
    }
}

After truffle compile and truffle migrate command I ran below command in truffle console:

HelloWorld.balance.call()

Error:

TypeError: Cannot read property 'call' of undefined at evalmachine.:1:19 at ContextifyScript.Script.runInContext (vm.js:35:29) at Object.exports.runInContext (vm.js:67:17) at TruffleInterpreter.interpret (/usr/lib/node_modules/truffle/lib/repl.js:99:17) at bound (domain.js:280:14) at REPLServer.runBound [as eval] (domain.js:293:12) at REPLServer. (repl.js:545:10) at emitOne (events.js:96:13) at REPLServer.emit (events.js:188:7) at REPLServer.Interface._onLine (readline.js:239:10)

truffle(default)> HelloWorld.deployed()
Contract {
  contract:
   Contract {
     _eth:
      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],
        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],
        iban: [Object],
        sendIBANTransaction: [Function: bound transfer] },
     transactionHash: null,
     address: '0x83367f99f17e89248c32f4a323c027446246e650',
     abi: [ [Object], [Object] ],
     Helloworld:
      { [Function: bound ]
        request: [Function: bound ],
        call: [Function: bound ],
        sendTransaction: [Function: bound ],
        estimateGas: [Function: bound ],
        getData: [Function: bound ],
        '': [Circular] },
     balance:
      { [Function: bound ]
        request: [Function: bound ],
        call: [Function: bound ],
        sendTransaction: [Function: bound ],
        estimateGas: [Function: bound ],
        getData: [Function: bound ],
        '': [Circular] },
     allEvents: [Function: bound ] },
  Helloworld:
   { [Function]
     call: [Function],
     sendTransaction: [Function],
     request: [Function: bound ],
     estimateGas: [Function] },
  balance:
   { [Function]
     call: [Function],
     sendTransaction: [Function],
     request: [Function: bound ],
     estimateGas: [Function] },
  allEvents: [Function: bound ],
  address: '0x83367f99f17e89248c32f4a323c027446246e650',
  transactionHash: null }
4

Just do

HelloWorld.deployed().balance.call()
  • ah.. Thanks.. Command is working.. But, the output is: { [String: '0'] s: 1, e: 0, c: [ 0 ] } It supposed to be 1000 as the balance variable is set to 1000. Sorry, I am new to this. – Ronak Patel Jan 11 '17 at 17:39
  • Your constructor function's capitalization is wrong. Should be HelloWorld. – Tjaden Hess Jan 11 '17 at 17:46
0

Referred to in this thread: https://ethereum.stackexchange.com/a/11944/16743. Truffle v.3.x requires you to invoke a function or variable using .then() as per the documentation here: http://truffleframework.com/tutorials/upgrading-from-truffle-2-to-3#contract-abstractions-deployed-is-now-thennable

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.