0

Let's say I have an array in my smartcontract that looks like this

string[] public employees;

I am able to fetch data from employees if I know the index, like this

contract.method["employees"].catchCall([i]); // i is the index

How am I supposed to get all items in employees if I don't know how many are there?

Divyanth Jayaraj
  • 950
  • 4
  • 12
  • 29

1 Answers1

1

If you are using a solidity version above 0.6 the ABIEncoderV2 is no longer considered experimental. Github Solidity 0.6 Release

With the new Encoder you can return dynamic arrays and structs.

pragma solidity >=0.6.0;
pragma experimental ABIEncoderV2;


contract SomeContract {
    string[] public employees;

    function getAllEmployees() public view returns (string[] memory) {
        return employees;
    }
}