Question: In my contract I have an array of token address with a size of 1000 elements, I want to create a function (which only read) to retrieve these values with this kind of logic:

address[] tokens;

function readArray() public view returns(RecordStruct[]) {
RecordStruct[] results;

for (uint256 i=0; i // do something
results.push({...});
}

return results;
}

So my question is: What is the limit of operations for a function who only reads?

Apr 30, 2023, 5:37 AM
Why would you need a function that make an iteration on an array in a smart contract when you could simply put this logic in the web application saving up on deployment gas?
Apr 30, 2023, 7:26 AM
Can’t you just make a view function that returns tokens?
Apr 30, 2023, 7:41 AM
there is no limit but it's not gas efficient if there is a internal call to it and may revert
I suggest using public array to get the needed index directly or mapping
Apr 30, 2023, 9:49 AM

© 2024 Draquery.com All rights reserved.