0

I use web3.py to read out a large amount of data and I cannot see what goes wrong here. getValue() and getValue2(), both can be called from remix.ethereum.org without an error, but when I use the python code I posted, then I can only read out getValue2(), the function getValue() throws an error and it looks like it runs in a gas limit. But since the function throws no errors called from remix.ethereum, I really don't see why there should be such a gas error:

Solidity Contract:

pragma solidity ^0.4.19;


contract TestContract {

   uint [1000000] val;
   uint [200000] val2;


   function TestContract(){

   }

   function getValue()  external view returns(uint [1000000]){
         return val;
   }
   
   function getValue2()  external view returns(uint [200000]){
         return val2;
   }
}

Python code:

import json
import web3

from web3 import Web3, HTTPProvider
from web3.contract import ConciseContract

# web3
w3 = Web3(HTTPProvider('https://ropsten.infura.io'))

# Instantiate and deploy contract
contractAddress = '0x37c587c2174bd9248f203947d7272bf1b8f91fa9'

with open('testfactory.json', 'r') as abi_definition:
    abi = json.load(abi_definition)

contract_instance = w3.eth.contract(contractAddress, abi=abi,ContractFactoryClass=ConciseContract)

arr2=contract_instance.getValue2() #works fine
print(len(arr2))

arr=contract_instance.getValue() #throws an error, posted below
print(len(arr))

testfactory.json:

[
    {
        "constant": true,
        "inputs": [],
        "name": "getValue2",
        "outputs": [
            {
                "name": "",
                "type": "uint256[200000]"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "getValue",
        "outputs": [
            {
                "name": "",
                "type": "uint256[1000000]"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "constructor"
    }
]

Error in Python:

Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\web3\contract.py", line 844, in call_contract_function
    output_data = decode_abi(output_types, return_data)
  File "C:\Python36\lib\site-packages\eth_abi\abi.py", line 109, in decode_abi
    return decoder(stream)
  File "C:\Python36\lib\site-packages\eth_abi\decoding.py", line 102, in __call__
    return self.decode(stream)
  File "C:\Python36\lib\site-packages\eth_utils\functional.py", line 22, in inner
    return callback(fn(*args, **kwargs))
  File "C:\Python36\lib\site-packages\eth_abi\decoding.py", line 140, in decode
    yield decoder(stream)
  File "C:\Python36\lib\site-packages\eth_abi\decoding.py", line 102, in __call__
    return self.decode(stream)
  File "C:\Python36\lib\site-packages\eth_utils\functional.py", line 22, in inner
    return callback(fn(*args, **kwargs))
  File "C:\Python36\lib\site-packages\eth_abi\decoding.py", line 198, in decode
    yield cls.item_decoder(stream)
  File "C:\Python36\lib\site-packages\eth_abi\decoding.py", line 102, in __call__
    return self.decode(stream)
  File "C:\Python36\lib\site-packages\eth_abi\decoding.py", line 165, in decode
    raw_data = cls.read_data_from_stream(stream)
  File "C:\Python36\lib\site-packages\eth_abi\decoding.py", line 247, in read_data_from_stream
    len(data),
eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes.  Only got 0 bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/Users/Sebi/PycharmProjects/web3/test.py", line 18, in <module>
    arr=contract_instance.getValue()
  File "C:\Python36\lib\site-packages\web3\contract.py", line 805, in __call__
    return self.__prepared_function(**kwargs)(*args)
  File "C:\Python36\lib\site-packages\web3\contract.py", line 866, in call_contract_function
    raise_from(BadFunctionCallOutput(msg), e)
  File "C:\Python36\lib\site-packages\web3\utils\exception_py3.py", line 2, in raise_from
    raise my_exception from other_exception
web3.exceptions.BadFunctionCallOutput: Could not decode contract function call getValue return data 0x for output_types ['uint256[1000000]']

Any suggestions what I could do? Is there a bug in web3.py v4.0?

TylerH
  • 20,799
  • 66
  • 75
  • 101
HansPeterLoft
  • 489
  • 1
  • 9
  • 28
  • I'm pretty sure this has to do something with a gaslimit, that is set in web3.py, but I don't know how I could change that? – HansPeterLoft Jan 30 '18 at 19:27
  • Ok, I got the problem, it's indeed a problem of gas: (https://ethereum.stackexchange.com/questions/23918/what-is-the-array-size-limit-of-a-returned-array-from-a-contract-function-call-i) but I see not yet how I could increase the gas limit in web3.py. Anyone an idea how this can be done? – HansPeterLoft Jan 31 '18 at 20:36

0 Answers0