0

I am trying to implement the simple storage.

When calling set function, the contract will append a new Log object to logs array, and also return the related index to the caller for reference data.

The problem is I cannot get returned index, it is always empty.

How can I get the index from calling set function?

pragma solidity ^0.5.0;

contract Storage {
    struct Log {
        string fname;
        string lname;
        string dob;
    }
    mapping (uint => Log) logs;

    uint index = 0;

    function set(string memory fname, string memory lname, string memory dob) public returns (uint) {
        index++;
        logs[index] = Log(fname, lname, dob);
        return (index);
    }

    function get(uint idx) public view returns (string memory, string memory, string memory) {
        return (logs[idx].fname, logs[idx].lname, logs[idx].dob);
    }
}

1 Answer 1

1

In Remix, you need to click on the [vm]from:0xca3... line in the console at the bottom after you've called the function. There will be a row in the table labeled decoded output which will give you the return value.

1
  • 1
    decoded output always empty, it is incorrect value
    – Alongkorn
    Commented Mar 26, 2019 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.