polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
239 stars 111 forks source link

Question: How to decode a call? #360

Closed BulatSaif closed 8 months ago

BulatSaif commented 8 months ago

Polkadot js have a tab to decode call, it accepts string and returns call object, is something similar possible with py-substrate-interface? Screenshot from 2023-10-30 20-05-33

arjanz commented 8 months ago

Of course, you can manually create an Extrinsic SCALE-object (in PolkadotJS apps it's titled "hex-encoded call" but in reality this is an "hex-encoded extrinsic", which of course contains the call. I personally think this is a bit misleading) and then decode the hex-encoded string. Something like:

extrinsic_obj = substrate.create_scale_object("Extrinsic")
extrinsic_obj.decode(ScaleBytes("0x280403000b8052d3818b01"))

print(extrinsic_obj.value)

And If you only want to decode the actual Call with corresponding hex-encoded string:

call_obj = substrate.create_scale_object("Call")
call_obj.decode(ScaleBytes("0x03000b8052d3818b01"))

print(call_obj.value)
BulatSaif commented 8 months ago

@arjanz, it works, thank you for explaining!