I am testing smart contracts in sandbox mode using python scripts.

I want to be able to store how much an operation cost. So for example when I get the output of a contract origination after baking a block (example below), I want to be able to store the value 26616000:

        This origination was successfully applied
        Originated contracts:
        Storage size: 630 bytes
        Paid storage size diff: 630 bytes
        Consumed gas: 26616000
        Balance updates:
          tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx ... -ꜩ0.63
          tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx ... -ꜩ0.257

I was hoping there might be a way to search for gas cost by using the operation hash or something like that? Or would there be other way I can store it?

2 Answers 2


There are many block indexers online that offer you the ability to enter an operation hash and get back all the relevant details, such as gas consumed and baker fee.

Check out TZKT: https://api.tzkt.io/

Injecting an operation returns an operation hash. There is no RPC API to fetch details based on an operation hash. The only way to do this with a "command" is to use the monitor API to check every block created, after your operation hits the mempool, to see if your operation is included. Then you can get all the details via the RPC for that block.

This will either require your application guaranteed to remain online until the block is published, or potentially having to scan a large number of blocks when you come back online. This is why people building applications rely on block indexers as they provide better solutions for these situations. You can find blocks and details by querying operation hash's at any point.

If you are designing a network that will run in sandboxed mode, and will have many such operations that you need to fetch, i'd consider deploying your own copy of an indexer in your network.

If you are using snadboxed mode, purely to do an experiment, why not move to the testnet, as then you will be able to use the testnet block indexer. Which will likely be how you would do it in "production" on the real network.

If this is a single, one off experiment, that is standalone from everything else, you could pipe the output from that command into a script and just try search for the text.

  • Thanks, I was looking for a command I could use locally on the Tezos node though. I'm running tests on sandbox mode so it's not on the main blockchain.
    – Darius
    Nov 13, 2020 at 17:34
  • @Darius see my edit
    – Simon McLoughlin
    Nov 14, 2020 at 12:57

You can find this information in the block where your operation inserted.

tezos-client rpc get /chains/main/blocks/<block-level>

Then under operations you can find your operation by hash, and then look under contents.metadata.operation_results.consumed_gas to see the amount of gas your operation used.

Attached is an example of a random operation I picked on a block explorer. If you look at the operation on a block explorer you'll see the consumed gas on the explorer lines up with the consumed gas in the block response from tezos-client. In this case, 1427 micro tez were consumed.


Your searching algorithm to find your operation can simply start at the latest block, and scan the operations in the 2-d operations array. If your transaction is not found then call the same rpc command for block - 1 until you do find it or go back long enough you're certain it hasn't yet been included.

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.