Having a block with all the extrinsics/events, what code should I write (preferably using polkadotJs) to compute the total amount of fees paid?
1 Answer
here you go:
const at = await api.rpc.chain.getFinalizedHead();
const block = await api.rpc.chain.getBlock(at);
const blockFees = await Promise.all(block.block.extrinsics.map(
(ext) => api.rpc.payment.queryInfo(ext.toHex(), at.toHex()))
);
blockFees.forEach((x) => console.log(x.partialFee.toHuman()))
Although, note that this does not take tips into account.
-
This doesn't work for extrinsic where the fees are refunded (like:
parachainSystem.enactAuthorizedUpgrade
), do you have a better solution ? Commented Mar 17, 2022 at 23:00