TransWikia.com

Function to return tuples throws error on frontend

Ethereum Asked by Mindful on December 5, 2021

I have similar functions like this and they work fine:

    function getBarsOfParticipant() external view returns (uint256[], uint16[], bool[]) {
    uint256[] barIds = participantToBarIds[msg.sender];

    uint256[] memory ids = new uint256[](barIds.length);
    uint16[] memory lengths = new uint16[](barIds.length);
    bool[] memory forSale = new bool[](barIds.length);

    for (uint16 i = 0; i <= barIds.length; i++) {
        Bar storage bar = bars[barIds[i]];
        ids[i] = barIds[i];
        lengths[i] = bar.length;
        forSale[i] = bar.forSale;
    }

    return (ids, lengths, forSale);
}

Although the above code compiles, I always get this error at the front-end:

enter image description here

Any suggestions?

One Answer

I think that you cannot return the tuple of array like this (uint256[], uint16[], bool[])

Just return an index of each element lile (uint256, uint16, bool); so you need to return length of the array and iterate in the dapp to get all the data.

Answered by Ha ĐANG on December 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP