There are some similar posts to this but none seem to be able to solve my problem.
I have a contract deployed with Truffle running with testrpc.
I want to access the value of a public uint variable named gameStatus defined in the deployed contract game variable as such:
uint public gameStatus = 23;
I have found two ways to do this:
game.gameStatus(function(err, res){
document.getElementById('amt').innerText = res;
});
And using the then operator from Promises.
game.gameStatus().then(function(result){
document.getElementById('tableamt').innerText = result;
});
The first method never affects the value of 'tableamt' in the HTML. And the second method always yields a value of '0' in the HTML.
The contract in both cases deploys without errors and web3 does not complain.
Any help is much appreciated.
Thanks!
web3.eth.getCode(contractAddress)and confirmed the contract is indeed deployed? – Xavier Leprêtre B9lab Jan 17 '17 at 16:41Uncaught Error: The MetaMask Web3 object does not support synchronous methods like eth_getCode without a callback parameter.
However when I do game.deployed() I get this:
Contract BettingOver : () address : "0x7881c3a33335a8cceb04b86131f4bf43db26dbd8" allEvents : () betEnd : () bettingEnd : () bettingStart : ()
So it looks like the variables are not being set during deploy?
– Carlos G. Oliver Jan 17 '17 at 17:20web3.eth.getCode(contractAddress, function(err, code) { console.log(code);})– Xavier Leprêtre B9lab Jan 17 '17 at 17:24web3.eth.getCode("0x7881c3a33335a8cceb04b86131f4bf43db26dbd8", function(err, code){ console.log(code)}); undefined VM245:1 0x– Carlos G. Oliver Jan 17 '17 at 17:330xmeans there is no code at the address. Of course your "functions" return0. – Xavier Leprêtre B9lab Jan 17 '17 at 17:50module.exports = function(deployer) { deployer.deploy(Modgame, 10, 120, 120); deployer.autolink();};and when I runtruffle migrateit says that the migration was done successfully. – Carlos G. Oliver Jan 17 '17 at 19:38