contract CommodityERC20Factory {

  // index of created contracts

  mapping (address => bool) public validContracts; 
  address[] public contracts;

  // useful to know the row count in contracts index

  function getContractCount() 
    public
    view
    returns(uint contractCount)
  {
    return contracts.length;
  }

  // get all contracts

  function getDeployedContracts() public view returns (address[] memory)
  {
    return contracts;
  }

  // deploy a new contract

  function newCommodityERC20(string memory name, string memory symbol, uint256 init, address owner)
    public
    returns(address)
  {
    CommodityERC20 c = new CommodityERC20(name, symbol, init, owner);
    validContracts[c] = true;
    contracts.push(c);
    return c;
  }
}
function getContractCount() 
  public
  view
  returns(uint contractCount)
{
  return contracts.length;
}

// useful to know the row count in contracts index