2

I wrapped a smart-contract generated in remix into a Java Project. Im trying to get the two values that return me this function.

function getValues(address _a) external returns(bool, uint32) {
    uint32 n= data[_a].number;
    return (true, n);
}

The problem is that the returned value is a TransactionReceipt. How can I recover bouth value; The boolean and the uint??

UnexpectedCharacter
  • 852
  • 1
  • 11
  • 30

2 Answers2

2

The problem is that the returned value is a transaction-receipt. How can I recover both values?

Add view to the function declaration, and the returned value will be a tuple (bool, uint32).

Otherwise (if there's something that you're not telling us about the function, for which it cannot be declared view), you'll need to emit an event with the return values, and fetch it from the transaction-receipt.

goodvibration
  • 26,003
  • 5
  • 46
  • 86
2

The function can be made view and then you can use call from web3. This won't make a transaction but will just execute the function on the node you are connected to. The result will be the values that you expect.

Hope this helps

Jaime
  • 8,340
  • 1
  • 12
  • 20
  • 1
    I change the function and I add the view. But When I wrapp the contract to a Java class. Still telling me that I have a TransactionRecepit return. Any idea? – UnexpectedCharacter Mar 04 '19 at 09:34
  • 1
    can you post your java script code?. remember you need to update the ABI in your code and use call with your contract method. – Jaime Mar 04 '19 at 10:48
  • 1
    I´m not using web3js. The library is the web3j. I think that the call method is not implemented – UnexpectedCharacter Mar 04 '19 at 11:03
  • 1
    i tell that because in the documentation I can´t find – UnexpectedCharacter Mar 04 '19 at 11:03
  • 1
    It is implemented, you should use EthCall method an example of how to make a call to contracts can be found here: https://docs.web3j.io/transactions.html?highlight=ethcall#querying-the-state-of-a-smart-contract – Jaime Mar 04 '19 at 11:21
  • 1
    docs for EthCall moved: https://docs.web3j.io/transactions/#querying-the-state-of-a-smart-contract – Buzz Moschetti Sep 23 '20 at 13:39