Polymesh
                                
                                 Polymesh copied to clipboard
                                
                                    Polymesh copied to clipboard
                            
                            
                            
                        Is Polymesh compatible with substrate?
Hi, I tried to call substrate.get_events, but the data I got could not be decoded successfully. Is there any special type? I am currently referring to https://github.com/ PolymeshAssociation/Polymesh/blob/develop/polymesh_schema.json
Btw, the polkadot.js.org could not display block details which has transfer event like me: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fmainnet-rpc.polymesh.network#/explorer/query/4921857
We have our own Polkadot.js webapp here: https://mainnet-app.polymesh.network/#/explorer/query/4921857 The error you are seeing is with how the webapp tries to summarize POLYX transfer. We had added some extra fields to the transfer event.
This works, thanks for your reply!
What substrate.get_events are you calling?  Is it a TypeScript/JS package or Rust package?
What
substrate.get_eventsare you calling? Is it a TypeScript/JS package or Rust package?
I used polkascan-lib to decode and call, get_events from https://github.com/polkascan/py-substrate-interface/blob/b48f51538b46ec6bcebcb40b023aa41257211021/substrateinterface/base.py#L1509
That library says that it supports most MetadataV14 chains, which we support now (since our v5.0 release last month).  With the v14 metadata, the polymesh_schema.json file shouldn't be needed, at least not for blocks produced after the v5.0 upgrade.
Maybe it needs some extra info for the type_registry_preset to support Polymesh.
Yes, I have tried most of the substrate coins successfully, but the polymesh has been failing to decode, maybe there are some infos missing.
Thank you for your willingness to help me, cause I have not updated this library synchronously for a long time, so it is not clear whether it is the problem with the library or the types I configured, I will try again
I am going to try that python library locally here.
Found the problem.  Most substrate chains have their runtime package just one level deep (Polkadot polkadot_runtime::Event), but Polymesh has an extra package level polymesh_runtime_mainnet::runtime::Event.  The python package scalecodec uses a *:: for each package level when searching for the Event type.
Add these line to the https://github.com/polkascan/py-scale-codec/blob/master/scalecodec/type_registry/polymesh-mainnet.json type registry file:
    "polymesh_runtime_develop::runtime::Event": "*::Event",
    "polymesh_runtime_testnet::runtime::Event": "*::Event",
    "polymesh_runtime_mainnet::runtime::Event": "*::Event",
I think you can download that file and use a local file instead of the built-in type registry files.
I will open a PR with scalecodec to add those lines.
It works! Thank you very much! I'm so grateful for your willingness to help me and try it yourself ❤️
Here is another way to patch in those types:
from substrateinterface import SubstrateInterface, Keypair
from substrateinterface.exceptions import SubstrateRequestException
# import logging
# logging.basicConfig(level=logging.DEBUG)
custom_types = {
    "types": {
        "polymesh_runtime_develop::runtime::Event": "*::Event",
        "polymesh_runtime_testnet::runtime::Event": "*::Event",
        "polymesh_runtime_mainnet::runtime::Event": "*::Event",
    }
}
try:
    substrate = SubstrateInterface(
        url="wss://mainnet-rpc.polymesh.network",
        type_registry=custom_types,
    )
except ConnectionRefusedError:
    print("⚠️ No local Substrate node running")
    exit()
events = substrate.get_events()
for event in events:
    print(f'* {event.value}')
Ok, now I am using a local JSON file 😄, I recorded the way you said.
Hi guys,
As @Neopallium pointed out, the path used for the Event type in the Polymesh runtime was incompatible with the current wildcard search in scalecodec (*::runtime::Event)
I suspect though this is because a recent change in Substrate (https://github.com/paritytech/substrate/pull/11981) so I made a generic solution for this.
I just released a fix in scalecodec package covering this: https://github.com/polkascan/py-scale-codec/releases/tag/v1.0.45
@arjanz Confirmed that works. Thanks for the quick fix.