I am writing tests with Foundry and trying to populate a dynamic array.

When I try:

        IAsset[] memory assets;
        uint256[] memory maxAmountsIn;

I get an error saying

Member "push" is not available in contract IAsset[] memory outside of storage.

When try

assets[0] = IAsset(OmniUSD)

I get an invalid opcode.

I would appreciate some clarity on what i am doing wrong


1 Answer 1


According to the Solidity docs, as opposed to storage arrays, it is not possible to resize memory arrays (e.g. the .push member functions are not available). You either have to calculate the required size in advance or create a new memory array and copy every element.

See: https://docs.soliditylang.org/en/v0.8.12/types.html#allocating-memory-arrays

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