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 1


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 ?
    – Crystalin
    Mar 17, 2022 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.