假设我的智能合约中有一个看起来像这样的数组
string[] public employees;
如果我知道索引,就可以从employees
获取数据
contract.method["employees"].catchCall([i]); // i is the index
如果我不知道其中有多少,该如何获得employees
中的所有物品?
答案 0 :(得分:1)
如果您使用的固体版本高于0.6,则ABIEncoderV2不再被视为试验性的。 Github Solidity 0.6 Release
使用新的Encoder,您可以返回动态数组和结构。
pragma solidity >=0.6.0;
pragma experimental ABIEncoderV2;
contract SomeContract {
string[] public employees;
function getAllEmployees() public view returns (string[] memory) {
return employees;
}
}