0

I am using web3 1.0 and testrpc, The following is my contract.

pragma solidity ^0.4.18;
contract LocalEthereum {

    event Created(bytes32 _tradeHash);
    uint32 value = 0;

    function addValue()  external {

        value = value + 1;
        Created(0x01);
    }

    function getValue()  returns (uint)  {

        return value;
    }
}

This is the js application.

   createValue(account){
      console.log('createEscrow');
      this.escrowContract.methods.addValue().send({from: account,gas:210000,gasPrice:5000000000})
                      .on('transactionHash', function(hash){
                          console.log('hash',hash);
                      })
                      .on('receipt', function(receipt){
                          console.log('receipt',receipt);
                      })
                      .on('confirmation', function(confirmationNumber, receipt){
                          console.log('confirmation',confirmationNumber);
                      })
                      .on('error', console.error);

  }



  this.escrowContract.methods.getValue().call({from: account})
                    .then(function(result){
                        console.log('getTestValue',result);
                    });

I have used createValue() multiple times, so the expected results is the value variable in the contract will be non-zero, however when calling the getValue() method, it is still zero value.

what is the problem?

---------------------------------------------------------------

it is wield that I changed the value to 10 instead of 0, but the method still return 0.

this.escrowContract.methods.getValue().call({from: account}) .then(function(result){ console.log('getTestValue',result); });

this is the testrpc console output of transcation and call method,

eth_sendRawTransaction

  Transaction: 0x0f22da3b8ee8bc286afab370dc0b38734e4c51eda2eb6d81176de8ac0a980fd8
  Gas usage: 21272
  Block Number: 8
  Block Time: Tue Jan 02 2018 12:26:22 GMT+0000 (GMT)

eth_getTransactionReceipt
eth_call 

everything seems to be normal.

0

The solidity works fine, I'm guessing you're just calling the whole js application at once.

Try throwing it after you get a success:

   createValue(account){
      console.log('createEscrow');
      this.escrowContract.methods.addValue().send({from: account,gas:210000,gasPrice:5000000000})
                      .on('transactionHash', function(hash){
                          console.log('hash',hash);
                      })
                      .on('receipt', function(receipt){
                          console.log('receipt',receipt);

                    this.escrowContract.methods.getValue().call({from: account})
                    .then(function(result){
                        console.log('getTestValue',result);
                    });
                      })
                      .on('confirmation', function(confirmationNumber, receipt){
                          console.log('confirmation',confirmationNumber);
                      })
                      .on('error', console.error);

  }

If this isn't the issue and you're calling it separately, I would just check to make sure it's going through properly on the testrpc

  • I am calling them separately one by one actually. I have used your method, still not working. I have checked my testrpc, all the transactions and calls are being recorded but js application receives zero. – user824624 Jan 2 '18 at 1:49
  • So the receipt on javascript is not logging correctly? Does a basic console.log(web3.eth.getBalance(account)) work? – thefett Jan 2 '18 at 2:41
  • the logging is correct in the testrpc console, it outputs the transaction receipt as well as the call, but calling doesn't return the data correctly. – user824624 Jan 2 '18 at 12:30

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.