I am writing a function to generate trail of all address who owned an asset ( assets is a mapping of asset no to owner no to address of owner). However while making array of address 'listofOwners' I get compilation error, Member "push" is not available in address[] memory outside of storage.

function viewTrail(uint256 _assetNo) public view returns(address[] memory){
   address[] memory listofOwners = new address[](assets[_assetNo].ownerNo);
  for(ownerNo = 1; ownerNo<= assets[_assetNo].ownerNo; ownerNo ++)

return listofOwners;}

Can you please suggest a solution or some other code to generate trail of owners of an asset?


1 Answer 1


You can assign the elements to the array position by referencing the element key like myArray[0] = ‘new value’;

The following example uses a view function, because the array is in memory:

function getMultipleAddresses( string[] calldata ids) public view returns (address[] memory) {

    address[] memory _addresses = new address[](ids.length);
    for (uint256 i = 0; i < ids.length; i++) {
      string memory id = ids[i];
      require(_idToAddress[id] != address(0), 'Missing address');
      address payable _address = payable(_addresses[i]);

      _addresses[i] = _address;
    return  _addresses;

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.