1

This question has two parts.

I would like to return a list of items from my smart contract in a simple way, ideally a one-liner solution, something that I consume on the front-end.

I tried some of the products listed here: https://medium.com/coinmonks/top-10-indexed-blockchain-data-apis-providers-3a43da97e54c

(but still dind't find a perfect match)

The objection / difficulty / concern that I have with using The Graph:

  • emit ChangeName(...)
  • emit ChangeDescription(...)

It feels like additional effort of emitting all the events, then writing handlers to reconcile the current state.

I just want to get the current list of items.

2. Is there a gas limit? (front-end only)

A really simple solution seems to use pragma experimental ABIEncoderV2

function getOrganisations() public view returns(Organisation[] memory) {
   return organisations;
}

It generates ABI, my front-end is able to load the data.

view functions don't actually consume gas when they're called from off-chain (because they don't change state)

Will MetaMask / Infura complain about the block size / amount data to return if the array grows to big?

I guess I'll have to try but if this is documented somewhere - please let me know 🙏

EDIT / UPDATE:

This is where I read about the limits: https://ethereum.stackexchange.com/a/121223/2524

Most RPC provider has a gas limit for eth_call t prevent spam and overloading of their infrastructure. Usually, it's about 2x-3x of the block gas limit. So as long as the gas of the view function is below your RPC providers limit, it should be fine.

1 Answer 1

1

Most RPC Provider will enforce a gasLimit for eth_call as DOS Protection. For instance, Alchemy has a limit of 550 mio. and Infura has a limit of 300 mio.

You can create a view function that retrieves the total number of organizations stored in the array and and another function that retrieves multiple organisations with a single call using multicall.

function numOrgs() public view returns(uint256) {
    return organisations.lenght;
}


function getOrganisations(uint256 idx) public view returns(Organisation memory) {
   return organisations[idx];
}

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.