【发布时间】:2020-10-15 12:41:49
【问题描述】:
按照本教程,我的 PC 上本地运行了一个 Substrate 节点。 https://substrate.dev/docs/en/tutorials/create-your-first-substrate-chain/interact。可以在两个端口上查看:
Local: http://localhost:8000/substrate-front-end-template
On Your Network: http://192.168.56.1:8000/substrate-front-end-template
所以我认为连接不是问题。
无论如何,我通过命令将@polkadot/api 绑定到我的节点:
yarn add @polkadot/api.
我现在在浏览器中遇到错误,每当我运行我的节点时:
Error Connecting to Substrate
Error: FATAL: Unable to initialize the API: createType(StorageKey):: Derived TypedArray constructor created an array which was too small
谁能帮忙?
【问题讨论】:
-
您是在运行未修改版本的节点模板,还是对其进行了更改?如果您对类型进行了更改,您可能需要在启动 API 连接时注册这些类型:polkadot.js.org/docs/api/start/types.extend
-
@DanForbes 除了将 'yarn add @polkadot/api' 放在基板前端模板中之外,我没有对类型进行任何更改。运行 'yarn add @polkadot/api' 会改变类型吗?
-
@DanForbes 我也找不到关于在哪里运行 JavaScript 文件以检索节点信息的文档(通过 API)。我是否在浏览器中将它们作为 sn-ps 运行?
-
你应该不需要将API添加到前端模板中,它已经有了github.com/substrate-developer-hub/substrate-front-end-template/…你可以在Node中运行脚本以及我在这里做的github.com/danforbes/polkadot-js-scripts跨度>
-
您可以从任何可以与节点建立连接的地方运行脚本,该节点可能在您的本地计算机或某个远程计算机上运行。要连接到节点,您不需要
require路径,而是使用要连接到的节点的 RPC 服务器的 URL 配置客户端库。例如,前端模板配置为连接到本地节点,但您可以更改此github.com/substrate-developer-hub/substrate-front-end-template/…
标签: api substrate polkadot polkadot-js