I have an array in smart contract:

contract SuperContract {
    uint[] public SuperArrayForExample;

    function addItemToArray(uint item) payable {

I try to get this array from JavaScript:

contract['SuperArrayForExample'](uint256).call().then(response => {
   console.log(response); // I would like to see my array here

I would like to see my array here but I get this error:

Uncaught (in promise) class org.tron.common.runtime.vm.program.Program$IllegalOperationException : Invalid operation code: opCode[fe];

The automatic getter that is generated will return only one element of your array and requires an input which will be the index of the element. You need to explicitly write your own getter function to get your array.

  • Thanks! May be do you know some methods to get array length ? – Шахтер Билли May 10 '19 at 6:24
  • Both in solidity and Web3 you can use the '.length' operation to find the length. For example SuperArrayForExample.length – Sanjay S B May 10 '19 at 8:37

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.