Subscan recently made a change to show estimated fee and used fee, while if you query data from sidecar, partial fee + tip = estimated fee. What is this used fee and how is it calculated?
1 Answer
You can guess the fee before call the function querying the information from the payment RPC methods.
A little script to query your example is:
const wsProvider = new WsProvider('wss://kusama-rpc.polkadot.io')
const api = await ApiPromise.create({ provider: wsProvider });
const blockHash = '0x9646cfeddaf4afd297f8a904f9458871b7203e6922cff502b3588af4c6cd1f0d';
const { block } = await api.rpc.chain.getBlock(blockHash);
// The extrinsic from your example(0x436d39517244cd5fc7c3d35dd08de0ccb62cb620868b5428db831857d4a952eb) is in block.extrinsics[7]
const extrinsic = block.extrinsics[7].toHex();
const queryFeeDetails = await api.rpc.payment.queryFeeDetails(extrinsic, blockHash);
console.log('queryFeeDetails:', JSON.stringify(queryFeeDetails.toHuman(), null, 2));
const queryInfo = await api.rpc.payment.queryInfo(extrinsic, blockHash);
console.log('queryInfo:', JSON.stringify(queryInfo.toHuman(), null, 2));
This will give return you:
queryFeeDetails: {
"inclusionFee": {
"baseFee": "33.3333 µKSM",
"lenFee": "489.9995 µKSM",
"adjustedWeightFee": "5.4706 µKSM"
}
}
queryInfo: {
"weight": "155,732,000",
"class": "Normal",
"partialFee": "528.8035 µKSM"
}
The estimated fee is partial fee, which is partial_fee = base_fee + len_fee + adjusted_weight_fee
But the adjusted_weight_fee
might slightly change depends in which block the extrinsic is included. I am not 100% sure how subscan calculates it, but this is the Used Fee field.
Check this response to see an excellent explanation about how to calculate the final fee: https://substrate.stackexchange.com/a/4224/2762