簡體   English   中英

無法在節點和運行時之間轉換參數“tx”:解碼字段 CheckMortality.0 時出錯

[英]Could not convert parameter `tx` between node and runtime: Error decoding field CheckMortality.0

我嘗試使用 polkadot-js libray 運行一個簡單的應用程序,用於在 plasm 上的 Dusty 帳戶之間傳輸令牌。 用於運行代碼段的源代碼和 package.json 可在此 git 存儲庫中找到

節點版本: 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 between node and runtime: Error decoding field CheckMortality.0: RuntimeApi, Execution: Could not convert parameter between node and runtime: Error decoding field CheckMortality.0 (node:13572) UnhandledPromiseRejectionWarning: Error: 1002: Verification Error: Execution: Could not convert parameter轉換參數tx between node and runtime: Error decoding field CheckMortality.0 (node:13572) UnhandledPromiseRejectionWarning: Error: 1002: Verification Error: Execution: Could not convert parameter between node and runtime: Error decoding field CheckMortality.0: RuntimeApi, Execution: Could not convert parameter tx between 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 between 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 between 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. (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 替換。 plasm-types 庫返回的字段可以在此文件中找到,格式為 json。

我試圖通過瀏覽節點模板存儲庫來找出錯誤的類型,但我無法弄清楚。 如何修復?

我不得不對類型定義做一些小改動來規避這個問題。 換句話說,替換:


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

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

為了


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

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

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

可以在此處此處找到有關此問題的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM