7

How would I have the following data structure be saved in an Ethereum contract using solidity?

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

The goal is for me to be able to easily access the array of structs associated to each user/address.

8

Here is an example :

pragma solidity ^0.4.2;
contract test {

  struct my_struct {
    int a;
  }

  mapping (address=>my_struct[]) Map;

  function fill_map(my_struct struct1,my_struct struct2) internal  {

    Map[msg.sender].push(struct1);
    Map[msg.sender].push(struct2);

  }
}
| improve this answer | |
  • How did you get this data by address(msg.sender) can you please show this? – urjit on rails Jun 11 '19 at 14:04
  • i didn't get your question!! – Badr Bellaj Jun 12 '19 at 20:19

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.