6

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?

Example on solidity pragma <=0.5.16: enter image description here

Example on solidity pragma >=0.6.0: enter image description here

2

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 and payable are deprecated and will be removed in the future. Instead, the stateMutability 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.


JSON format for v0.6.0

{
    "inputs": [],
    "name": "getX",
    "outputs": [
        {
            "internalType": "uint256",
            "name": "",
            "type": "uint256"
        }
    ],
    "stateMutability": "view",
    "type": "function"
},

JSON format for v0.5.13

{
    "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
  • This makes sense, thank you for the well-detailed answer – João Quintanilha Jan 14 at 9:13
  • 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 at 22:09
  • 1
    @RickPark I'm agree, so I updated my answer with that information. – alberto Jan 14 at 22: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.