arrays – How to Access Arrays from Public Struct Mapping in Solidity

arraysmappingstruct

I have this struct:

struct Amendment {
    string text;
    uint24 textColor;
    bool isRadialGradient;
    uint8[2] radialGradientCenterPct;
    uint16 linearGradientAngleDeg;
    uint24[2][11] gradientColors;
    uint messageId;
    uint inReplyToMessageId;
    address sender;
    address recipient;
    uint sentAt;
}

This mapping:

mapping(uint => Amendment) public amendmentMapping;

and this function:

function getAmendment(uint tokenId) public view returns (Amendment memory amendment) {
    return amendmentMapping[tokenId];
}

When I retrieve an Amendment via this function it works correctly. However, when I get an Amendment via the amendmentMapping directly the response does not include the arrays radialGradientCenterPct and gradientColors.

Ideally I would not have a separate getter, so I am curious whether this is a real limitation or whether I'm making a mistake.

Best Answer

It depends on your Solidity version, so sharing this might help. There are a couple questions with answers around this that might help: