1

I am trying to find the correct parameters to pass into the query function for the substrate interface module when interacting with the parallel api to interact with their AMM. I attempted to modify the code from the linked post:

How to determine which parameters are required when using substrate.query() to query a storage_function from polkascan's py-substrate-interface?

Below is my adapted code:

from substrateinterface import SubstrateInterface

paraurl = 'wss://rpc.parallel.fi'

substrate = SubstrateInterface(
    url=paraurl,
)

storage_function = substrate.get_metadata_storage_function('AMM','Pools')

typeString = storage_function.get_params_type_string()
print('Storage Function params length:', len(typeString))


# Retrieve a SCALE object of the param type
param_type = substrate.create_scale_object(storage_function.get_params_type_string()[0])

# Possible options of Enum type
print(param_type.type_mapping)

token_param = substrate.create_scale_object(param_type.type_mapping[0][1])

# Show possible options
print(token_param.type_mapping)

However, I am receiving the error:

  File "/home/travnado300/Documents/Python Scripts/Substrate Interactions/Parallel.py", line 30, in <module>
    token_param = substrate.create_scale_object(param_type.type_mapping[0][1])
  TypeError: 'NoneType' object is not subscriptable

I am wondering if this is just an issue with the parallel API not having all of the information available or if there is a way to access the params needed to pass into the function:

substrate.query()
3
  • You can check it manually with the PolkadotJS website. Or do you really need to figure this out dynamically? Aug 4, 2022 at 10:45
  • Can i check the required parameters there? I would like the code to be dynamic to pull the query on its own, but i do not need to check the parameters dynamically. Aug 4, 2022 at 20:59
  • Did you check the link? You can select Amm::pools there and see the signature of (u32, u32) -> Option<PalletTraitsPool>. Aug 5, 2022 at 10:07

2 Answers 2

1

You can use the storage_function.get_param_info() to get more information about the param types:

storage_function = substrate.get_metadata_storage_function('AMM', 'Pools')

param_info = storage_function.get_param_info()

print(param_info)
# [{'primitive': 'u32'}, {'primitive': 'u32'}]

More information see: https://github.com/polkascan/py-substrate-interface#type-information-about-how-to-format-parameters

0

I am wondering if you are missing a step here, before using param_type. Possibly a decode() after create_scale_object, similar to https://github.com/polkascan/py-scale-codec/blob/master/README.md#encode-a-call

Your Answer

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

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