微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在节点和运行时之间转换参数“tx”:错误解码字段 CheckMortality.0

如何解决无法在节点和运行时之间转换参数“tx”:错误解码字段 CheckMortality.0

我尝试使用 polkadot-js libray 来运行一个简单的应用程序,用于在 plasm 上的 Dusty 帐户之间传输令牌。用于运行代码片段的源代码和 package.json 位于 this git repo

节点版本: v12.8.2
纱线版本​​: 1.22.5



const { ApiPromise,WsProvider } = require('@polkadot/api')
const { Keyring } = require('@polkadot/keyring')
const plasmDeFinitions = require('@plasm/types/interfaces/deFinitions');
const jsonDeFinitions = require('./types.js')
const fs = require('fs')
const BN = require('bn.js')

startChain()

async function startChain() {
  console.log("trying connection to ",process.env.RPC_URL)
  const targetAddress = process.env.TARGET_ADDRESS
  const provider = new WsProvider(process.env.RPC_URL)
  const types = Object.values(plasmDeFinitions).reduce(
      (res,{ types }) => ({ ...res,...types }),{},);

  const api = new ApiPromise({
      provider,types
  });

  api.on('connected',() => console.log(`Connected to ${process.env.RPC_URL}`));
  api.on('disconnected',() => console.log(`disconnected from ${process.env.RPC_URL}`));
  await api.isReady;
  const [chain,nodeName,nodeVersion] = await Promise.all([
    api.rpc.system.chain(),api.rpc.system.name(),api.rpc.system.version()
  ])

  console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion} - ${process.env.RPC_URL}`)

  const keyring = new Keyring({ type: 'sr25519' })
  const fromPair = keyring.addFromUri(process.env.PLASM_MNEMONIC)
  const fromAmountUnits = new BN('1000000000000000')
  const transfer = api.tx.balances.transfer(targetAddress,fromAmountUnits)      
  // send value
  //const nonce = await api.query.system.accountNonce(process.env.FROM_ADDRESS)
  const nonce = await api.rpc.system.accountNextIndex(process.env.FROM_ADDRESS)
  console.log("got nonce",nonce)
  const txHash = await transfer.signAndSend(fromPair,{nonce})

}

堆栈跟踪:

trying connection to wss://rpc.dusty.plasmnet.io/ Connected to wss://rpc.dusty.plasmnet.io/ You are connected to chain Dusty using Plasm Node v1.6.1-cf15b11-x86_64-linux-gnu - wss://rpc.dusty.plasmnet.io/ got nonce Type { negative: 0,words: [ 0 ],length: 1,red: null,registry: TypeRegistry {} } 2021-02-05 21:00:27 RPC-CORE: submitExtrinsic(extrinsic: Extrinsic): Hash:: 1002: Verification Error: Execution: Could not convert parameter txbetween node and runtime: Error decoding field CheckMortality.0: RuntimeApi,Execution: Could not convert parametertxbetween node and runtime: Error decoding field CheckMortality.0 (node:13572) UnhandledPromiseRejectionWarning: Error: 1002: Verification Error: Execution: Could not convert parametertxbetween node and runtime: Error decoding field CheckMortality.0: RuntimeApi,Execution: Could not convert parametertxbetween node and runtime: Error decoding field CheckMortality.0 at RpcCoder._checkerror (<mydir>\examples\plasm-simple-transfer\node_modules\@polkadot\api\node_modules\@polkadot\rpc-provider\coder\index.js:84:13) at RpcCoder.decodeResponse (<mydir>\examples\plasm-simple-transfer\node_modules\@polkadot\api\node_modules\@polkadot\rpc-provider\coder\index.js:47:10) at WsProvider.value (<mydir>\examples\plasm-simple-transfer\node_modules\@polkadot\api\node_modules\@polkadot\rpc-provider\ws\index.js:214:90) at W3CWebSocket.value [as onmessage] (<mydir>\examples\plasm-simple-transfer\node_modules\@polkadot\api\node_modules\@polkadot\rpc-provider\ws\index.js:194:153) at W3CWebSocket._dispatchEvent [as dispatchEvent] (<mydir>\examples\plasm-simple-transfer\node_modules\yaeti\lib\EventTarget.js:107:17) at W3CWebSocket.onMessage (<mydir>\examples\plasm-simple-transfer\node_modules\websocket\lib\W3CWebSocket.js:234:14) at WebSocketConnection.<anonymous> (<mydir>\examples\plasm-simple-transfer\node_modules\websocket\lib\W3CWebSocket.js:205:19) at WebSocketConnection.emit (events.js:315:20) at WebSocketConnection.processFrame (<mydir>\examples\plasm-simple-transfer\node_modules\websocket\lib\WebSocketConnection.js:554:26) at <mydir>\examples\plasm-simple-transfer\node_modules\websocket\lib\WebSocketConnection.js:323:40 (node:13572) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag--unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:13572) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

此外,当我尝试清除运行(删除 node_modules 并重新安装)时,我收到相同的消息,但字段 CheckMortality 被 CheckNonce 替换。可在 this file 中以 json 格式找到 plasm-types 库返回的字段。

我试图通过浏览节点模板存储库来弄清楚哪些类型是错误的,但我无法弄清楚。怎么修?

解决方法

我不得不对类型定义做一些小改动来规避这个问题。换句话说,替换:


  const types = Object.values(plasmDefinitions).reduce(
      (res,{ types }) => ({ ...res,...types }),{},);

  const api = new ApiPromise({
      provider,types
  });

为了


  const types = Object.values(plasmDefinitions).reduce(
      (res,);

  types["Address"] = "IndicesLookupSource";
  types["LookupSource"] =  "IndicesLookupSource";

  const api = await ApiPromise.create({
    provider: provider,types: types
  });

有关此问题的更多信息可以在 herehere

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。