javascript - 使用 api.rpc.payment.queryFeeDetails 获取外部费用
问题描述
我想使用api.rpc.payment.queryFeeDetails
api 调用(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
我做错了什么?
解决方案
基于@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"
}
推荐阅读
- python - 如何使用 rcParams 重置 Matplotlib 样式表
- docker - 构建错误。无法获取 http://deb.debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages
- scala - 我想在 Scala 中将 org.apache.spark.rdd.RDD[(Any, scala.collection.immutable.Iterable[String])] 展平为 String
- reactjs - 托管在 Firebase 上时,React 路由器不会路由流量
- java - 如何使用 Jsonb 库从 Postgres 读取 jsonb
- mpandroidchart - mpAndroidChart:Xaxis.setPosition 到 Bottom_Inside 在 HorizontalBarChart 上不起作用
- javascript - 使用 Next.js 动态导入节点模块
- java - 从文本文件中提取分离的代码并将其存储到数组中以供进一步使用
- python - 用不同的字符串结尾搜索相同的字符串开头
- python - 在 pythonista Objc_util 中使用 UINotificationFeedbackGenerator