I am querying extrinsic data and I am able to fetch gasLimit and gasPrice out of Extrinsic.method.args. But how do I fetch the amount of gas used from an extrinsic?

  • Hi, are you using contracts or pallets? Because gas is a contract specific terminology while pallets use weights to determine the cost of a transaction . Please do clarify
    – islami00
    Apr 22, 2022 at 11:16
  • @islami00 it's a contract
    – user2395
    Apr 22, 2022 at 11:22

3 Answers 3


Gas and weight are one and the same concept when it comes to pallet-contracts. We merely kept the name gas for historic reasons. The gas limit you supply to the contracts.call extrinsic directly influences the weight of the extrinsic (1to1 translation).

So what you want to index is the system.ExtrinsicSuccess or system.ExtrinsicFailed event emitted by the contracts.call exrinsic. It contains a weight field which tells you the overall weight of the extrinsic. This is essentially the gas that was consumed + static overhead of the extrinsic.

I think things get clearer when you look at the weight annotation of the call extrinsic:

pub fn call() { ... }
  • Hi! thank you for the answer! is it the same in moonbeam too?
    – user2395
    Apr 25, 2022 at 10:59


Click the image for better resolution

With a contracts call extrinsic there will be an associated event ExtrinsicSuccess where you can deduce the gas consumed. You may want to look at using an indexer.


If you are using the Polkadot API, you need to check the Contract section (https://polkadot.js.org/docs/api-contract/start/contract.read/):

const { gasConsumed, result, output } = await contract.query.get(alicePair.address, { value, gasLimit });

Interacting with your contract (querying or executing functions) will return information like the gasConsumed in the execution, as shown above.

  • thing is, i'm not interacting with any contracts. I'm merely indexing the details of previous interactions on chain.
    – user2395
    Apr 22, 2022 at 15:38

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.