As of Solidity 0.6.0+ compiler, my remix shows getter functions, built by public variables, as transactions and, therefore, do not return the value. I searched the solidity 0.6.0 breaking changes but I didn't find any explanation to this. What am I missing?
The problem is related to the ABI JSON produced by the compiler and how the tools use it to determine if a function is view
or pure
.
As you can see in the docs:
The fields
constant
andpayable
are deprecated and will be removed in the future. Instead, thestateMutability
field can be used to determine the same properties.
Now, see how different are the JSON generated using the following simple contract:
contract C1 {
uint x;
function setX(uint _x) public {
x = _x;
}
function getX() public view returns (uint) {
return x;
}
}
Please, note that only the ABI for the getX()
function is shown.
{
"inputs": [],
"name": "getX",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getX",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
EDIT:
As we can see here, Remix used only the constant
field to determine if a function is view
or pure
.
var lookupOnly = args.funABI.constant
Now, this is solve, as we can see here.
const lookupOnly = args.funABI.stateMutability === 'view' || args.funABI.stateMutability === 'pure' || args.funABI.constant
-
-
I do not think that “probably remix use the field constant but I cannot confirm that” be a so definitive answer to justify to mark the question as “answered”. Upvote it if it is useful, but if you mark it as “answered” nobody will finish the work. – Rick Park Jan 14 '20 at 22:09
-
1