0

I have struct Receipt { bytes32 domainName; uint256 amountPaid; uint256 timeBought; } mapping(address => Receipt[]) public receipts; I am trying to retrieve the whole array with web3.js like this: this.DDNSCore.methods.receipts(checksumAddress).call(); And I get the aforementioned error. If I give an integer index as a second parameter to the function, it manages to retrieve me the Receipt, which is at that index of the array.
Is there a way to get the whole array?

  • Returning structs in public functions in solidity is an experimental feature and it is not fully supported by web3js. – Ismael Mar 10 '18 at 18:37
1

You can write a view function into your smart contract which returns the array, but this will only be accessible from JavaScript etc. and NOT callable from other smart contracts.
Limitations of the EVM prevent dynamically sized return types.

  • With that approach I am getting Invalid solidity type: tuple[]. related question – Arnaudov_St Mar 10 '18 at 0:57
  • 1
    That's probably because Receipt is a struct type, which is not supported yet (but they're working on it!). Your custom view function should return something more specific (like receipts[addressParam].domainName) and you can have more than one. Alternatively, you could remember that reads are free (in the sense of gas) and just do a lot of reads. – WBT Mar 10 '18 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.