1

I'm using the Mist wallet just to display the contents of the contract.
Bellow, you can see the code to access the contract function (submitUnits) and the result of the LoadScript when I run in the console.

call_function.js call_function.js
In the last commented row, you can see the value I want to print (100).

enter image description here Mist wallet

enter image description here

However it always returns this hex number. How can i get the Total Units that is mentioned in the wallet screenshot?

The code of the contract is this:

contract UCounter {
mapping (address => uint256) public UnitsFrom;
uint256 public TotalUnits;

function submitUnits(uint256 Units) returns (uint ){
    UnitsFrom[msg.sender] = Units;
    TotalUnits = Units;
    return TotalUnits;
}

}

Hope someone could help. Thanks.

  • 0x2c1e75ec... is the function you are sending, not the result of the function – Joe Jul 26 '17 at 16:30
  • 2
    please give the code of the contract otherwise it is hard to debug. e.g.: is the function that you call constant? – Validity Labs - Sebastian Jul 26 '17 at 16:31
  • @ValidityLabs-Sebastian I update the code up in the contract code. Thanks. – JC_92 Jul 27 '17 at 8:02
0

The function getData return function call parameters encoded together with the function signature.

From the snippet of your abi submitUnits is not constant has input parameter of type uint256. The output type is cropped, but in this case since submitUnits is a transaction not a call, and for transaction we can recover the return value.

From the documentation to execute a transaction we have to do:

var txid = MyContractInstance.submitUnits.sendTransaction(parameter, { from: eth.accounts[3] });
console.log(txid);

And you have to wait until the transaction is mined in the blockchain.

To read a variable, or call a constant method you have to make a call

MyContractInstance.TotalUnits.call(function (value) {
    console.log(value);
});
  • Yes I understood @Ismael , but with the transaction I alway can send values to my contract. What i'm looking for is through the geth console access the TotalUnits variable. How can I return the value of the Transaction? I have updated the post with the wallet contract. – JC_92 Jul 27 '17 at 12:35
0
web3.eth.getStorageAt (address, position)

Here address is address of your smart contract, and position is state variable position, in your case position=1 because TotalUnits is the second variable in your contract, and variables are numbered starting from zero.

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.