0

I have been stuck on this for a while, I have a mapping
mapping (uint => bytes) idToEmail;

A function to populate the mapping
function addRecord(uint id, bytes email) public payable { idToEmail[id] = email; }

I need a function to fetch multiple values for an input of multiple keys, like
function fetchRecords(uint[] ids) returns (bytes[]) {..}

How do I go about doing this?

1 Answer 1

1

You cannot return a dynamic array in solidity at the moment however, you can return a byte array of fixed size. Try Solidity: Can you return dynamic arrays in a function? for more information

4
  • Can I concatenate or serialize the elements of the dynamic array and return that as a string?
    – Shivam D
    Commented Sep 14, 2017 at 14:34
  • yes you can, solidity doesn't support concatenation but you can manually concatenate bytes together and return a string representation like so: ethereum.stackexchange.com/questions/729/… Commented Sep 14, 2017 at 14:43
  • Also, note that you can use the solidity-stringutils package to split strings : github.com/Arachnid/solidity-stringutils Commented Sep 14, 2017 at 14:48
  • Great! :) I'm assuming that since contract calls are inexpensive (free?) this operation should not cost anything?
    – Shivam D
    Commented Sep 14, 2017 at 16:00

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.