2
uint16[] ALLITEMS;

function _get() public view returns(uint16[] memory){
    uint16[] memory _list = ALLITEMS;
    return _list;   
}

should I use "memory" or "storage" to call this? eventually, I may want to return 200-500 items here if needed. will this function fail?

2
  • Please, can you clarify and add more details about your question? Aug 9, 2022 at 15:34
  • It depends on the purpose. By using memory it will create a copy of the array in memory and then again on the return. By using storage _list will be a reference to the storage location and only there will a copy to memory when returning. In any case you could write the function and evaluate them for gas consumption.
    – Ismael
    Aug 10, 2022 at 4:56

1 Answer 1

2

As far as I know there's no limit to how many array items you can get from a view function IF you're calling it from outside the blockchain meaning you're using web3.js or a client library to access the data from the blockchain.

IF you're accessing the array from another smart contract you'll end up running into gas limits because even though it's a view function, it takes some gas to access each item. So you'll be able to read about 200 items from the array when calling it form the smart contract.

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.