Skip to content

In hardhat fund-me -- why can we access a mapping or array by passing parameters to a function? #563

Discussion options

You must be logged in to vote

If you have a public state variable of array type, then you can only retrieve single elements of the array via the generated getter function. This mechanism exists to avoid high gas costs when returning an entire array. You can use arguments to specify which individual element to return, for example, myArray(0).

The same applies to mappings.

You should read more here: https://docs.soliditylang.org/en/v0.8.13/contracts.html#getter-functions

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@amanbthakkar
Comment options

Answer selected by amanbthakkar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants