Need this architecture

      address1 => [struct1, struct2],
      address2 => [struct1, struct2, struct3,],
      address3 => [struct1, struct2, struct3, struct4, struct5],

My Attempt

contract Gallery{
uint public emojiCount;
struct Token {
    uint token;
    string ipfsHash;
mapping (address => Token[]) public emoji;

function addEmoji (uint _token, string _ipfsHash) public {
   emojiCount ++;
   emoji[msg.sender].push(Token(_token, _ipfsHash));

How do i return Struct array so that i can save Images IPFS String according to user account address [msg.sender] .

How is this possible in solidity
Thanks in advance

marked as duplicate by Ha ĐANG, Soham Lawar, Achala Dissanayake, Paul Berg, Ismael Sep 13 '18 at 14:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


your code should work as intended, and give you a total count of 'emojis', but you may want that information on a per address basis, to do that you could add a second mapping, to always hold the last position for the inserted address:

mapping (address => uint256) addressToLastUsedPosition;

then when you do a push on the array, and get the position back, and set the mapping.

uint256 newMaxPositionForAddress = emoji[msg.sender].push(Token(_token, _ipfsHash));
addressToLastUsedPostion[msg.sender] = newMaxPositionForAddress;

doing so will always allow you to know how many 'emoji' are per address.

  • Thank you it's work for me . I think solution you explain with solidity code is much easier to understand , where similar question are as mention above are not self explanatory @shaddow – Syed Zain Ali Sep 19 '18 at 5:49

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