3

I want to use api.rpc.payment.queryFeeDetails api call ( https://polkadot.js.org/docs/substrate/rpc#queryfeedetailsextrinsic-bytes-at-blockhash-feedetails) to get information about fees of a specific extrinsic in a Substrate blockchain.

I'm using this code to do it:

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));

But I'm getting this error:

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

What I'm doing wrong?

  • "Unable to query dispatch info.: Execution, ApiCould not convert parameter `uxt` between node and runtime: Invalid transaction version" -- are you using the correct api version for the endpoint you are trying to access? What versions (node, api, etc.) are you using? try to update? – Nuke Apr 05 '21 at 19:27
  • I think it's not the problem as I can reproduce it on Kusama blockchain using latest versions of the stack: 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); const info = await api.rpc.payment.queryFeeDetails(block.extrinsics[1], blockHash); console.log(JSON.stringify(info, null, 2));``` – Mario Pino Uceda Apr 05 '21 at 19:35
  • strange: works with no error (or output) for me with your code snippet https://i.stack.imgur.com/OQGCv.png --- on https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-rpc.polkadot.io#/js / are you sure of the blockhash and network? – Nuke Apr 05 '21 at 22:01
  • https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-rpc.polkadot.io#/explorer/query/0x7289009f27b3ec756f8bdfb0272307c06bc4fee8bf5f83c89201ce36e49d9a90 I see no block here on kusama – Nuke Apr 05 '21 at 22:03
  • 1
    try `api.rpc.payment.queryFeeDetails(block.extrinsics[1].toHex(), blockHash);` – kianenigma Apr 06 '21 at 07:35
  • 1
    Yes NukeManDan, I fixed the hash in the snippet, you can try now with kiaenigma modification and any kusama block hash to get tx fee. – Mario Pino Uceda Apr 06 '21 at 08:18

1 Answers1

3

Full working snippet based on @kiaenigma answer:

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));

Output:

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"
}