3

我想使用api.rpc.payment.queryFeeDetailsapi 调用(https://polkadot.js.org/docs/substrate/rpc#queryfeedetailsextrinsic-bytes-at-blockhash-feedetails)来获取有关 Substrate 区块链中特定外部费用的信息。

我正在使用这段代码来做到这一点:

const blockHash = '0x8ad4960941190d155b22bf3c1c6aeacb4cdcfcc87b519a87106be7dfd342ae1d';
const { block } = await api.rpc.chain.getBlock(blockHash);
const info = await api.rpc.payment.queryFeeDetails(block.extrinsics[1], blockHash);
console.log(JSON.stringify(info, null, 2));

但我收到了这个错误:

2021-04-05 18:37:35        RPC-CORE: queryInfo(extrinsic: Bytes, at?: BlockHash): RuntimeDispatchInfo:: 1: Unable to query dispatch info.: Execution, ApiCould not convert parameter `uxt` between node and runtime: Invalid transaction version
Error: 1: Unable to query dispatch info.: Execution, ApiCould not convert parameter `uxt` between node and runtime: Invalid transaction version
    at RpcCoder._checkError (/root/test/node_modules/@polkadot/rpc-provider/coder/index.cjs:84:13)
    at RpcCoder.decodeResponse (/root/test/node_modules/@polkadot/rpc-provider/coder/index.cjs:47:10)
    at WsProvider.value (/root/test/node_modules/@polkadot/rpc-provider/ws/index.cjs:231:90)
    at W3CWebSocket.value [as onmessage] (/root/test/node_modules/@polkadot/rpc-provider/ws/index.cjs:211:153)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/root/test/node_modules/yaeti/lib/EventTarget.js:107:17)
    at W3CWebSocket.onMessage (/root/test/node_modules/websocket/lib/W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (/root/test/node_modules/websocket/lib/W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (events.js:315:20)
    at WebSocketConnection.processFrame (/root/test/node_modules/websocket/lib/WebSocketConnection.js:554:26)
    at /root/test/node_modules/websocket/lib/WebSocketConnection.js:323:40

我做错了什么?

4

1 回答 1

3

基于@kiaenigma 答案的完整工作片段:

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-rpc.polkadot.io#/js

const blockHash = '0x8ad4960941190d155b22bf3c1c6aeacb4cdcfcc87b519a87106be7dfd342ae1d';
const { block } = await api.rpc.chain.getBlock(blockHash);
console.log('extrinsic:', JSON.stringify(block.extrinsics[1].toHuman(), null, 2));
const queryFeeDetails = await api.rpc.payment.queryFeeDetails(block.extrinsics[1].toHex(), blockHash);
console.log('queryFeeDetails:', JSON.stringify(queryFeeDetails.toHuman(), null, 2));
const queryInfo = await api.rpc.payment.queryInfo(block.extrinsics[1].toHex(), blockHash);
console.log('queryInfo:', JSON.stringify(queryInfo.toHuman(), null, 2));

输出:

extrinsic: {
  "isSigned": true,
  "method": {
    "args": [
      {
        "Id": "FJLFJeKagZ8xkDxH4AneGN9tRe9NZM65CZFdbnhVz6Whm2u"
      },
      "12.9452 KSM"
    ],
    "method": "transferKeepAlive",
    "section": "balances"
  },
  "era": {
    "MortalEra": {
      "period": "1,024",
      "phase": "559"
    }
  },
  "nonce": "15,942",
  "signature": "0x63866b9d4dd0a5b2240c3a864bf1184ed764fb02eecc950a0c480e1a887c3643ea3625960a1e4e808a3171684c173a3eb099183433eaf54b4a94367406334d08",
  "signer": {
    "Id": "HmFYPT1btmi1T9qqs5WtuNJK93yNdnjjhReZh6emgNQvCHa"
  },
  "tip": "0"
}
queryFeeDetails: {
  "inclusionFee": {
    "baseFee": "166.6666 µKSM",
    "lenFee": "2.4666 mKSM",
    "adjustedWeightFee": "243.0000 pKSM"
  }
}
queryInfo: {
  "weight": "182,428,000",
  "class": "Normal",
  "partialFee": "2.6333 mKSM"
}
于 2021-04-06T11:29:55.987 回答