0

I have contract in solidity and I like to return array or array by index.

I'm using experimental feature on, and in remix in solidity I don't have issue with returing the array, but when I use web3 from react, the array is empty. I've tried to get all array elements and I've tried changing the contract to get array by index, but no luck.

I've edited the question, so I've tried with latest version of web3, at this current time is 1.2.4, and when I try to get element from array by index, I'm getting the error below.

pragma solidity >=0.5.0 <0.7.0;
pragma experimental ABIEncoderV2;

Function from the contract

function getItem(uint index) public view returns (string memory) {
    return loadedItems[index];
}

Function called in react

const item = await WoW.methods.getItem(1).call();
this.setState({ item });

Function returns empty array.

EDIT

With latest web3 version 1.2.4 I'm getting this error: Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.

I'm kind of new with this one, but from stack trace web3 failing on this:

ABICoder.prototype.decodeParameters = function (outputs, bytes) {
  if (outputs.length > 0 && (!bytes || bytes === '0x' || bytes === '0X')) {
    throw new Error('Returned values aren\'t valid, did it run Out of Gas? ' + 'You might also see this error if you are not using the ' + 'correct ABI for the contract you are retrieving data from, ' + 'requesting data from a block number that does not exist, ' + 'or querying a node which is not fully synced.');
  }

BR, Igor

  • Comments are not for extended discussion; this conversation has been moved to chat. – eth Nov 16 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.