In my solidity code, I am not using the global variable msg.* but still I get the error message in the function. Please explain why this function needs to be a Payable function

The below snippet is taken from https://github.com/imperialsoftech/coffee-supplychain-ethereum I just changed the compiler version to ^0.5.8 in truffle

enter image description here

/*get farm inspector data*/
function getFarmInspectorData(address batchNo) public onlyAuthCaller view returns (string memory coffeeFamily,
                                                                                   string memory typeOfSeed,
                                                                                   string memory fertilizerUsed){

    farmInspector memory tmpData = batchFarmInspector[batchNo];
    return (tmpData.coffeeFamily, tmpData.typeOfSeed, tmpData.fertilizerUsed);


modifier onlyAuthCaller() {
    lastAccess = msg.sender;   **<---------- this is the state variable getting updated.**
        authorizedCaller[msg.sender] == 1,
        "You are not authorized");

I suspect this error message is misleading.

Try changing this:

farmInspector memory tmpData = batchFarmInspector[batchNo];

To this

farmInspector storage tmpData = batchFarmInspector[batchNo];

We can't see the whole picture, so I'm assuming batchFarmInspected is an array or a mapping of struct farmInspector. storage will make it a storage pointer and you should be able to return the three values, as expected.

See here for more details: https://blog.b9lab.com/storage-pointers-in-solidity-7dcfaa536089

Hope it helps.

  • mapping (address => farmInspector) batchFarmInspector; I tried to change like this farmInspector storage tmpData = batchFarmInspector[batchNo]; Still the same error.. The snippet is taken from github.com/imperialsoftech/coffee-supplychain-ethereum I just changed the compiler version to ^0.5.8 in truffle – iappmaker Jul 8 at 2:50
  • I understand that payable is used to access the global variable msg.* .. do we need that if we need to update the state variable ? – iappmaker Jul 8 at 2:59
  • No. Only msg.value. msg.sender is always available. – Rob Hitchens - B9lab Jul 8 at 4:52

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.