【问题标题】:How to use Polkadot-js API with Substrate Node Template?如何将 Polkadot-js API 与 Substrate 节点模板一起使用?
【发布时间】:2020-03-12 19:18:46
【问题描述】:

在 Substrate 生态系统中,通常通过分叉 Substrate Node Template 来开始编写新的区块链节点。用户界面有几个选项(例如Appsfront-end-template),它们都基于相同的底层Polkadot-JS API

某些版本的 API 可以在没有任何自定义配置的情况下使用某些版本的节点模板,但通常必须为 API 提供有关节点使用的类型的信息。提供类型的过程记录在 https://polkadot.js.org/api/start/types.extend.html#impact-on-extrinsics我需要提供哪些类型

【问题讨论】:

    标签: substrate


    【解决方案1】:

    2020 年 3 月 10 日,Substrate 节点模板 here 引入了类型不兼容的更改。我将使用术语“旧”和“新”来指代此日期之前和之后。

    直接使用 API

    如果您使用带有 polkadot-js API 的新节点模板,您将需要使用以下类型,如文档中所述 here

    {
      "Address": "AccountId",
      "LookupSource": "AccountId"
    }
    

    使用前端包

    问题中提到的前端都已更新,以减轻用户的生活。应用程序 UI here 和前端模板 here。但是,如果您尝试将旧节点模板与新前端一起使用,反之亦然,则需要进行一些自定义类型注入。

    老节点模板,老前端

    无需自定义类型

    新节点模板,新前端

    无需自定义类型

    旧节点模板,新前端

    {
      "Address": "GenericAddress",
      "LookupSource": "Address"
    }
    

    新节点模板,旧前端

    {
      "Address": "AccountId",
      "LookupSource": "AccountId"
    }
    

    如何注入类型

    在应用中

    转到左侧的Settings 选项卡和顶部的Developer 选项卡。将类型粘贴进去。

    在前端模板中

    修改此文件https://github.com/substrate-developer-hub/substrate-front-end-template/blob/dff9783e29123f49a19cbc43f5df7ae010c92775/src/config/common.json#L4

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 2020-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      相关资源
      最近更新 更多