如何在基板中生成 types.json

问题描述

polkadot-js 中提供给开发者在托盘中定义自定义类型,以便 polkadot-ui 可以理解这些类型(这意味着可以使用一些底层 API polkadot-js)。这些类型是使用 json 格式定义的。这是例子

{
  "TransactionInput": {
    "parent_output": "Hash","signature": "Signature"
  },"TransactionOutput": {
    "value": "u128","pubkey": "Hash","sale": "u32"
  },"Transaction": {
    "inputs": "Vec<TransactionInput>","outputs": "Vec<TransactionOutput>"
  }
}

我看到在 substrate-node-template/scripts 中有生成 types.json 的 aggregrate_types.js 文件。我不知道如何自动生成它或者我应该手写。 例如,在我的托盘中,我定义了 enum RoleIDstruct Role。但是在 UI 中它不理解 RoleID 是什么。你能解释得更清楚吗?我相信它可以与定义types.json有关。

enter image description here

https://github.com/polkadot-js/apps/blob/master/packages/page-settings/src/md/basics.md#developer

aggregrate_types.json:

enter image description here

谢谢!!!

解决方法

目前,手动生成它是遵循文档 here 的最佳方法。据我所知,没有干净的方法可以自动生成它,但很快你就不需要在 Substrate this PR lands 中担心它!