Compiling below code:
pragma solidity ^0.4.2;
contract HelloWorld {
uint public balance;
function Helloworld(){
balance = 1000;
}
}
truffle(default)> HelloWorld.balance.call()
Error:
TypeError: Cannot read property 'call' of undefined
at evalmachine.
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.
at emitOne (events.js:96:13)
at REPLServer.emit (events.js:188:7)
at REPLServer.Interface._onLine (readline.js:239:10)
This looks like a bug in truffle, please file a bug report there.
I have also encountered the same issue. How did you solve it?
Hi @jeanjluo : You need to use HelloWorld.deployed().balance.call()
I know this is a fairly old thread, but I'm running the same exact code and running into the same problem. HelloWorld.deployed().balance.call() results in the same error; TypeError: Cannot read property 'call' of undefined. Any idea for a work around?
@steveO1234 @rnkhouse @chriseth @jeanjluo
Try This:
HelloWorld.deployed().then(helloworld=> console.log(helloworld.balance.call()))
OR
HelloWorld.deployed().then(function(instance){helloworld=instance})
helloworld.balance.call()
@daljeetv +1 for your answer. Bingo
8 oct 17 truffle 4.0 beta - problem still actual (((
truffle(develop)> MetaCoin.deployed().then(ct => console.log(ct.creator.call()))
Promise {
undefined
truffle(develop)> (node:16379) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): Error: Invalid number of arguments to Solidity function
undefined
truffle(develop)>
This looks like a problem in Truffle. Please report it to them.
Most helpful comment
@steveO1234 @rnkhouse @chriseth @jeanjluo
Try This:
OR