1

I am trying to use py-substrate-interface to query the acalaOracle.value for Acala/Karura. Below I show a screenshot of how to get the data using polkadot{js}. Here is the python code I am trying:

url = 'wss://acala-rpc-0.aca-api.network'
substrate = SubstrateInterface(url)
hash = substrate.get_chain_finalised_head()
timestamp = substrate.query(module='Timestamp',storage_function='Now',block_hash=hash).value
block = substrate.get_block_number(hash)
result = substrate.query('AcalaOracle', 'Values', params = [{'Token': 'KSM'}], block_hash = block)

I am getting an error substrateinterface.exceptions.SubstrateRequestException: {'code': -32602, 'message': 'invalid type: integer 1234601, expected a (both 0x-prefixed or not) hex string with length of 64 at line 1 column 7'}, so I am not defining the parameter correctly. Would anyone know how to do that?

I tried to following the examples given in this question, but I still can't figure it out. The following code:

result_map = substrate.query_map('AcalaOracle', 'Values')
print(list(result_map))

returns

[[<scale_info::50(value={'Token': 'ACA'})>, <scale_info::495(value={'value': 264510000000000000, 'timestamp': 1655316318429})>], [<scale_info::50(value={'Token': 'DOT'})>, <scale_info::495(value={'value': 7051400000000000000, 'timestamp': 1655316318429})>]]

but I still don't know what to pass as the parameter.

acalaOracle.value

0

2 Answers 2

2

The call is complaining about you sending an integer. You will be getting an integer from get_block_number which you're passing in a block_hash field:

block = substrate.get_block_number(hash) # this is an integer

result = substrate.query('AcalaOracle', 'Values', params = [{'Token': 'KSM'}], block_hash = block)

Since you already appear to have the hash, simply pass that instead of the block number.

result = substrate.query('AcalaOracle', 'Values', params = [{'Token': 'KSM'}], block_hash = hash) # pass hash here instead
1

To get more information how to format the paramaters of a specific storage function, you can check out: https://github.com/polkascan/py-substrate-interface#type-information-about-how-to-format-parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.