Return an array from a Solidity function

jwgcarlylejwgcarlyle Member Posts: 29
Hi

Is it possible to return an array from a function call? Specifically, I want an array of IDs of in-progress crowd-funding opportunities from a crowd-funding contract.

The documentation is unclear on this and I can't find any examples.

Thanks if you can help
James

Comments

  • chrisethchriseth Member Posts: 170 ✭✭✭
    This is not yet possible. Arrays can only be used in state and as parameters (not return parameters) of external functions:
    https://github.com/ethereum/wiki/wiki/Solidity-Tutorial#arrays

    The feature is quite high on the priority list, though.
    Note that due to a limitation of the EVM, returning variably-sized arrays from message-calls will only work for transactions, not internal calls. The reason is that the size of the returned data has to be known beforehand.
  • jwgcarlylejwgcarlyle Member Posts: 29
    Many thanks (again!). I'd be interested in how others are working around this (indeed, have others even wanted to get more than one record out of a contract in a reporting mechanism).

    I am also listening to state changes and transaction calls in the contract via events, which are working reliably for me, but they can only be used to track events (I think) while the client is listening. My simple use-case would be a mechanism for a web-app to connect to a node, and retrieve all in-progress items in a contract (e.g. a crowd-funding contract, which can support multiple simultaneous funding drives). I see that the filter watch can specify a from and to: block, so I will test whether a JSON / HTML UI client can disconnect from the node and then reconnect later and start listening again, and pick up all events from the last time it connected. But it would still imply that the UI client needs to maintain the contract state, based on events it accumulated, rather than being able to query multiple records in the contract in one go.

    An alternative would be for a standalone application to maintain parallel state in a separate database, but this forms a single point of failure.

    Please shout if I am completely misunderstanding the issue :)
  • SmithgiftSmithgift Member Posts: 64
    I believe logs are actually in the blockchain, so filters should be able to get old stuff with .get()
  • AronVanAmmersAronVanAmmers Amsterdam, NetherlandsMember Posts: 40 ✭✭
Sign In or Register to comment.