0

while everything is working fine when working on remix ide but on truffle its not updaing value of a property (player2)

i am also returning that address value and its returning as it should be. but not updating in contract;

app.js

joinGame: function() {
    App.contracts.TicTacToe.deployed().then(function(instance) { 
        instance.joinGame.call()
        .then(function(res) { 
          console.log(res);
          $('#joinBtn').hide();
        });
    });
  },

tictactoe.sol

function joinGame() public payable returns(address) {
     //require(msg.value > 0, 'value should be more than 0');
        require(msg.sender != player1, 'both player cant be same');
        player2 = msg.sender;
        player2Escrow = 100; // need to update this with msg.value;
        return player2;
    }

although i am returning address from which i am calling as player2 (only when calling join function) but stil while fetching player2 value is 0x0

pls help.

  • 1
    You're using a call, which can't make any state changes. You need to use a transaction. Note that transactions don't have return values. – smarx Sep 4 at 7:20
  • changed still nothing happend code joinGame: function() { App.contracts.TicTacToe.deployed().then(function(instance) { instance.joinGame.call({ from : web3.eth.accounts[1], }) .then(function(res) { web3.eth.sendTransaction({ from : web3.eth.accounts[1], nonce : 0 }, function(err, transactionHash) { if (err) { console.log(err); } else { console.log(transactionHash); } }); }); }); }, code – rohit roy Sep 4 at 7:54
  • You're still doing a call: instance.joinGame.call. If you're using Truffle, this page might help: trufflesuite.com/docs/truffle/getting-started/…. (See also github.com/trufflesuite/truffle/tree/master/packages/…) Otherwise please tell us what library you're using. – smarx Sep 4 at 8:05
  • i am using below function for that and its working but calling two times, dnt know why....instance.performMove(xpos, ypos, {from:web3.eth.accounts[0]}) .then(function(res) { web3.eth.sendTransaction({ from : web3.eth.accounts[0], gas : 21000, value : 100 }, function(err, transactionHash) { if (err) { console.log(err); } else { console.log(transactionHash); } }); }); – rohit roy Sep 4 at 10:42
  • That code sends two transactions: one to call performMove and one for web3.eth.sendTransaction, which attempts to transfer 100 wei and will invoke the contract's fallback function. – smarx Sep 4 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.