How to access the variables of an array?

Viewed 71

I have the following variables in my contract.

 20     struct Order {
 21         address investor;
 22         uint amount;
 23         string investorId;
 24         uint timestamp;
 25     }
 26 
 27     Order[] public orders;
 28 

A buy call pushes a new order like so:

 34     function buy(string memory investorId) public payable {
 35         orders.push(Order(msg.sender, msg.value, investorId, now));
 39     }

And when I'm accessing orders using truffle, I get the following:

truffle(develop)> instance.orders(2)
Result {
  '0': '0x96AB9a654abFde8a0c88B18D8c2F9FeAB047C147',
  '1': BN {
    negative: 0,
    words: [ 46661632, 5986771, 444, <1 empty item> ],
    length: 3,
    red: null
  },
  '2': 'investor-1',
  '3': BN {
    negative: 0,
    words: [ 15984231, 24, <1 empty item> ],
    length: 2,
    red: null
  },
  investor: '0x96AB9a654abFde8a0c88B18D8c2F9FeAB047C147',
  amount: BN {
    negative: 0,
    words: [ 46661632, 5986771, 444, <1 empty item> ],
    length: 3,
    red: null
  },
  investorId: 'investor-1',
  timestamp: BN {
    negative: 0,
    words: [ 15984231, 24, <1 empty item> ],
    length: 2,
    red: null
  }
}

I cannot access the values with a dot: truffle(develop)> instance.orders(2).investorId gives undefined. How do I access the values? Secondly, the uint values, like the amount and the timestamp are being shown as the BN data-structure and not showing the actual values. How to see the actual values?

0 Answers
Related