2

I am currently working on a project involving Tezos smart contracts, and I'm using Taquito to interact with the Tezos blockchain. I'm trying to calculate the total fees spent on a confirmed transaction, including the baker's fee and the storage cost.

From what I can tell, the result: OperationContentsAndResult object returned when an operation is confirmed contains a fee field (which I assume represents the baker's fee) and a storage_limit field. My current approach is to calculate the total fee as fee + storage_limit * 250 mutez.

However, it feels like I might be reinventing the wheel here. Is there a built-in function or feature in Taquito that allows you to get the total fees (in XTZ) spent on a transaction? If not, is my current approach correct, or is there a better way to calculate this?

1 Answer 1

0

For a single operation, I'll suggest go through op.operationResults[0].metadata.balance_updates and op.operationResults[0].metadata.operation_result.balance_updates and add up the change value of the object property contract match the source. This is an example of operationResults for your reference

[
  {
    "kind": "transaction",
    "source": "tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys",
    "fee": "401",
    "counter": "462459",
    "gas_limit": "1101",
    "storage_limit": "0",
    "amount": "1000000",
    "destination": "tz1VWci3kmwzdwFWiQFzPJKyYLSjtsGarkSh",
    "metadata": {
      "balance_updates": [
        {
          "kind": "contract",
          "contract": "tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys",
          "change": "-401",
          "origin": "block"
        },
        {
          "kind": "accumulator",
          "category": "block fees",
          "change": "401",
          "origin": "block"
        }
      ],
      "operation_result": {
        "status": "applied",
        "balance_updates": [
          {
            "kind": "contract",
            "contract": "tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys",
            "change": "-1000000",
            "origin": "block"
          },
          {
            "kind": "contract",
            "contract": "tz1VWci3kmwzdwFWiQFzPJKyYLSjtsGarkSh",
            "change": "1000000",
            "origin": "block"
          }
        ],
        "consumed_milligas": "1000040"
      }
    }
  }
]
1
  • It's an interesting idea, but it's hard to distinguish which balance updates related to the fees and which are sent to the contract entrypoint.
    – ztepler
    May 17 at 17:09

Your Answer

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

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