Use custom types (Substrate FRAME pallet + Polkadot/Substrate frontend)

ⅰ亾dé卋堺 提交于 2021-01-24 08:45:12

问题


Scenario: You are developing a FRAME pallet for a custom Substrate node that uses custom types within Storage or Events. To interact with your custom Substrate node, you use the Polkadot/Substrate frontend

Problem:

  1. When you query the storage that contains your custom type, the frontend returns "unknown" as the value
  2. When you submit an extrinsic to be included in a block that should lead to the emission of an event using the custom type, the Polkadot/Substrate frontend seems to get stuck while stating that the extrinsic is "ready" for inclusion in a block. This is not the case though, if you inspect the block the extrinsic should be included in, you can see the following error message:

Unable to retrieve the specified block details. createType(Vec):: Struct: failed on 'data':: Cannot construct unknown type YOUR_CUSTOM_TYPE


回答1:


Solution: You have to specify your custom types in the Polkadot/Substrate frontend. To do so, select "Settings" -> "Developer" in the top menu bar:

Below you can see a text field titled "Additional types as a JSON file". In this text field you have to enter your custom types for the frontend to be able to interpret those correctly. In the top right corner, right below the version numbers, a big white question mark in a gray circle should be visible. By clicking on this question mark, an help dialog slides in.

Example configuration: Let's take the pallet I learned this lesson with as an example. In the highlighted lines, you see the custom enum "States":

pub enum States {
    Propose,
    VotePropose,
    Concern,
    VoteConcern,
    VoteCouncil,
}

Using the help dialog (the white question mark), it turns out that the correct configuration JSON snippet looks like this:

"States": {
    "_enum": [
        "Propose",
        "VotePropose",
        "Concern",
        "VoteConcern",
        "VoteCouncil"
    ]
}


来源:https://stackoverflow.com/questions/64601832/use-custom-types-substrate-frame-pallet-polkadot-substrate-frontend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!