0

I've written the following contract

contract Catalog{
    address[] internal array;


    function pushItem(address _el) external{
         array.push(_el);
    }

    function getArray() external returns(address[]){
         return array;
    }
 }

I've deployed it on a local Javascript VM with Remix. Then I've called pushItem(0x.....) but, when I invoke getArray() the following output is returned:

error: Failed to decode output: TypeError: Cannot read property 'length' of undefined

Any idea why and how to solve this problem?

0

I think your issue is that you are incorrectly pushing to the array. When pushing an address you need to do it like so: pushItem("0x..."). You are currently pushing to the array like so: pushItem(0x...). Also you may as well limit your getArray() external to getArray() external view since you're only looking at the data.

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.