Question on how to represent transaction fee

Hi there,

wondering on how to represent the transaction fees in /block response, for example:

A transferred 500CURR to B and payed 1CURR to Miner as a transaction fee

Should the fee be represented as payment from A to Miner ?

{
    "transaction": {
        "transaction_identifier": {
            "hash": "0x2f23fd8cca835af21f3ac375bac601f97ead75f2e79143bdf71fe2c4be043e8f"
        },
        "operations": [
            {
                "operation_identifier": {
                    "index": 1,
                    "network_index": 0
                },
                "type": "Transfer",
                "status": "Success",
                "account": {
                    "address": "{Address of A}"
                },
                "amount": {
                    "value": "-500",
                    "currency": {
                        "symbol": "CURR",
                        "decimals": 8
                    }
                }
            },
            {
                "operation_identifier": {
                    "index": 2,
                    "network_index": 0
                },
                "type": "Transfer",
                "status": "Success",
                "account": {
                    "address": "{Address of B}",
                },
                "amount": {
                    "value": "500",
                    "currency": {
                        "symbol": "CURR",
                        "decimals": 8,
                    }
                }
            },
            {
                "operation_identifier": {
                    "index": 3,
                    "network_index": 0
                },
                "type": "Transfer",
                "status": "Success",
                "account": {
                    "address": "{Address of A}"
                },
                "amount": {
                    "value": "-1",
                    "currency": {
                        "symbol": "CURR",
                        "decimals": 8,
                    }
                }
            },
            {
                "operation_identifier": {
                    "index": 4,
                    "network_index": 0
                },
                "type": "Transfer",
                "status": "Success",
                "account": {
                    "address": "{Address of Miner}"
                },
                "amount": {
                    "value": "1",
                    "currency": {
                        "symbol": "CURR",
                        "decimals": 8,
                    }
                }
            }
        ]
    }
}

:wave: @pkosin

Most teams represent this as a “transfer” as you have done above, however, they typically use a distinct Operation.Type to avoid confusion, like “fee”. I would also recommend zero-indexing your operations and using RelatedOperations to associate related single-party operations.

Using your example, this would look like:

{
  "transaction": {
    "transaction_identifier": {
      "hash": "0x2f23fd8cca835af21f3ac375bac601f97ead75f2e79143bdf71fe2c4be043e8f"
    },
    "operations": [
      {
        "operation_identifier": {
          "index": 0
        },
        "type": "Transfer",
        "status": "Success",
        "account": {
          "address": "{Address of A}"
        },
        "amount": {
          "value": "-500",
          "currency": {
            "symbol": "CURR",
            "decimals": 8
          }
        }
      },
      {
        "operation_identifier": {
          "index": 1
        },
        "related_operations": [
          {
            "index": 0
          }
        ],
        "type": "Transfer",
        "status": "Success",
        "account": {
          "address": "{Address of B}"
        },
        "amount": {
          "value": "500",
          "currency": {
            "symbol": "CURR",
            "decimals": 8
          }
        }
      },
      {
        "operation_identifier": {
          "index": 2
        },
        "type": "Fee",
        "status": "Success",
        "account": {
          "address": "{Address of A}"
        },
        "amount": {
          "value": "-1",
          "currency": {
            "symbol": "CURR",
            "decimals": 8
          }
        }
      },
      {
        "operation_identifier": {
          "index": 3
        },
        "related_operations": [
          {
            "index": 2
          }
        ],
        "type": "Fee",
        "status": "Success",
        "account": {
          "address": "{Address of Miner}"
        },
        "amount": {
          "value": "1",
          "currency": {
            "symbol": "CURR",
            "decimals": 8
          }
        }
      }
    ]
  }
}

Hope that helps!

Thanks a lot, make a lot of sense, our implementation followed :pray:

1 Like