py-substrate-interface icon indicating copy to clipboard operation
py-substrate-interface copied to clipboard

KeyError: 'gasRequired' when reading contract data from a chain

Open minhnd-dev opened this issue 2 years ago • 1 comments

I'm trying to read data from a substrate chain (Jupiter A1 testnet), I got this error:

Traceback (most recent call last):
  File "shibuya_interface.py", line 31, in <module>
    result = contract.read(keypair, 'get')
  File "/home/minhnd/anaconda3/lib/python3.8/site-packages/substrateinterface/contracts.py", line 796, in read
    contract_exec_result.gas_required = response['result']['gasRequired']
KeyError: 'gasRequired'

This is my code:

from substrateinterface import Keypair

substrate = SubstrateInterface(
    url="wss://ws.jupiter-poa.patract.cn/",
    ss58_format=42
)

contract = ContractInstance.create_from_address(
    contract_address="3g2kZxvk8XT8XLoDgJHYuNnEPN1t6yfP8vFj4jgxSWrUxGqJ",
    metadata_file="./flipper_metadata.json",
    substrate=substrate
)

keypair = Keypair.create_from_mnemonic("my secret phrase")

result = contract.read(keypair, 'get')
print('Current value of "get":', result.contract_result_data)
print(result)

This file runs perfectly on a substrate node template on my computer.

minhnd-dev avatar Feb 28 '22 10:02 minhnd-dev

I hardcoded a value for the gas_required in the contracts.py and it did temporarily fix the problem.

minhnd-dev avatar Feb 28 '22 10:02 minhnd-dev