I am trying to set a string and receive it back from my contract.

This is my code

    import web3
import json

from web3 import Web3
def main():
    w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
    w3.eth.defaultAccount = w3.eth.accounts[0]
    with open('abi', 'r') as abi_definition:
        abi = json.load(abi_definition)
    contract = w3.eth.contract(address=w3.toChecksumAddress('0x82A978B3f5962A5b0957d9ee9eEf472EE55B42F1'),abi=abi)
    get = contract.functions.getID().call()

if __name__ == '__main__':

I am getting following error

Traceback (most recent call last):
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/web3/contract.py", line 1214, in call_contract_function
    output_data = decode_abi(output_types, return_data)
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_abi/abi.py", line 63, in decode_abi
    return decoder(stream)
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_abi/decoding.py", line 99, in __call__
    return self.decode(stream)
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_utils/functional.py", line 22, in inner
    return callback(fn(*args, **kwargs))
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_abi/decoding.py", line 135, in decode
    yield HeadTailDecoder.as_decoder(tail_decoder=decoder)(stream)
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_abi/decoding.py", line 99, in __call__
    return self.decode(stream)
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_abi/decoding.py", line 113, in decode
    start_pos = decode_uint_256(stream)
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_abi/decoding.py", line 99, in __call__
    return self.decode(stream)
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_abi/decoding.py", line 162, in decode
    raw_data = cls.read_data_from_stream(stream)
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/eth_abi/decoding.py", line 244, in read_data_from_stream
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 "/home/sapan/PycharmProjects/GlobalCA/Node.py", line 18, in <module>
  File "/home/sapan/PycharmProjects/GlobalCA/Node.py", line 14, in main
    get = contract.functions.getID().call()
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/web3/contract.py", line 979, in call
  File "/home/sapan/PycharmProjects/GlobalCA/venv/lib/python3.5/site-packages/web3/contract.py", line 1236, in call_contract_function
    raise BadFunctionCallOutput(msg) from e
web3.exceptions.BadFunctionCallOutput: Could not transact with/call contract function, is contract deployed correctly and chain synced?
  • The code you shared doesn't include the line of code in the stack trace. – user19510 Apr 7 '18 at 2:48
  • Sorry, I was messing around with the code previously. I edited it now. Thanks – saps13 Apr 7 '18 at 4:20

This line might be wrong:


if you're changing the status, as the name suggest, it should be

  • Thanks that did solve the issue. Can I also view the value returned in python ? – saps13 Apr 7 '18 at 6:33
  • transactions usually return a transaction hash than can be used to retrieve the transaction information and the receipt – mirg Apr 7 '18 at 9:05

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.