Excellent question. This was the same problem that had me stumped too, until I saw @Briomkez's answer with reference to the yellow paper as well as the other answers .
In case someone doesn't understand his excellent but slightly technical answer or needs to see it in code action, please see below:
Please copy-paste the below sample (modified from the usual Remix default storage sample for this purpose) into Remix. Deploy it using "Injected Web3" option in Remix which will use Metamask for deployment on any testnet like Ropsten/Rinkeby.
- First set a value by calling the Store() method with a value (e.g.
2021). Note that this will not return any value in the decodedoutput field.
- Next call the retrieve2() method and examine the output in the
remix log window. The decodedoutput field will be empty.
- Next call
the retrieve() method and examine the decodedoutput field. It will
show the value properly.
Code Sample
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Storage {
uint number; //state variable
function store(uint num) public returns (uint) {
number = num;
//even this will not return any value in the decoded output field
return num; }
//the retrieve() view function will return a value in the
// "decodedoutput" field of the transaction
function retrieve() public view returns (uint){
return number;
}
// this method (not being a view method) will not return a value
function retrieve2() public returns (uint){
return number;
}
}
Explanation: The Yellowpaper states that the decodedoutput field will be ignored in the case of transactions, but will be filled out in the case of view functions etc.
Hope this helps!