I am writing a function that adds an element to a list of structs, where each element has a nested struct inside. I know it is NOT the most efficient way to do so, but enough for a PoC. In any case, my code consists of:

external[] mylist;

struct external {
  string id;
  string name1:
  internal[] internalList;

struct internal {
  string name2;
  uint256 ammount;

function addElement(string memory _id,
                    string memory _name1,
                    string memory _name2,
                    uint256 _ammount ) public restricted{
   internal memory intl = internal(_name2, _ammount);
   myList.push(external(_id, _name1, intl);

You can forget about the restricted modifier;

The error I am getting here is on the 'intl' struct and it says:

Invalid type for argument in function call. Invalid implicit conversion from struct Contract_Name.internal memory to struct Contract_Name.internal memory[] memory requested.

So I assume it is pretty obvious, but I have no clue of how to fix it and make it work. Please help

1 Answer 1


seems like creating a mapping for an Internal struct will be better inside your External struct. Something like

 struct External {
  string id;
  string name1:
  mapping (uint => Internal) internals;

maybe be this will help,to understand struct, check out this example

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.