I'm trying to get the chain state information from substrate using RPC for IdentityOf of any Accountid Upon succesfull request, I get the following result:

    "jsonrpc": "2.0",
    "result": "0x040200000002000c9924370e00000000000000000000000e4272696768746c797374616b65001a68747470733a2f2f6272696768746c797374616b652e636f6d00157374616b696e6737706340676d61696c2e636f6d00000f406272696768746c797374616b65",
    "id": 1

How can I decode the result specifically using Python's scale library?


1 Answer 1


Is there a specific reason why you manually want to decode raw SCALE-data? Because SCALE is without context, you need the exact type definition of the storage function and even specific runtime where you got that result from.. The type definitions are contained in the metadata of the runtime, where you can find the type definition of that storage function.

So the easiest way would be for example:

result = substrate.query("Identity", "IdentityOf", ["DWUAQt9zcpnQt5dT48NwWbJuxQ78vKRK9PRkHDkGDn9TJ1j"])

This function will take care of all that. You can even query historic values (state at block_hash):

result = substrate.query("Identity", "IdentityOf", ["DWUAQt9zcpnQt5dT48NwWbJuxQ78vKRK9PRkHDkGDn9TJ1j"], block_hash="0x21b90597ae8dba9b2bfcbedc2b94bf709172477d47bb845bfe4e23af9ecc87af")

But if you insist on decoding manually, what you can try is:

storage_function = substrate.get_metadata_storage_function("Identity", "IdentityOf")
value = substrate.decode_scale(storage_function.get_value_type_string(), ScaleBytes("0x040200000002000c9924370e00000000000000000000000e4272696768746c797374616b65001a68747470733a2f2f6272696768746c797374616b652e636f6d00157374616b696e6737706340676d61696c2e636f6d00000f406272696768746c797374616b65"))

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.