1

Suppose i have a loop. Here user is a struct of which player is an address.

address[] memory addrs = new address[](n);
for(uint i=0;i<n;i++){
addrs[i] = user.player;
}
 return addrs;

This is a view function so i know i wont have to pay to run it. Is this going to fail if the value of n increases beyond a point? Im confused about the gas block limit.

Sundeep Kumar
  • 147
  • 2
  • 10

1 Answers1

1

It depends on how you use it.

If you are calling it from your backend system through a node there is no gas limit as the call never goes inside a block. The call is simply made to the node and the node returns the required information - the blockchain network is not consulted at all. So the only restrictions are your node's throughput and computation power.

However if you call such a function from a non-view smart contract then the regular gas limits and gas payments are in place. So, yes, if your n is too big then you will hit the block gas limit and/or transaction gas limit at some point.

Lauri Peltonen
  • 29,391
  • 3
  • 20
  • 57