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) {
        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);

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
    decoded output always empty, it is incorrect value
    – Alongkorn
    Mar 26 '19 at 2:38

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.