Given a Tx message, how does one calculate the fee paid for the transaction?

7

Given a Tx message, how does one calculate how big a fee one paid for the transaction?

ThePiachu

Posted 2011-12-15T19:04:56.673

Reputation: 41 594

Answers

5

Use the following pseudocode:

TotalOutputValue = 0
For each Output in tx_out array
  TotalOutputValue += Output[value]
TotalInputValue = 0
For each Input in tx_in array
  PreviousOutput = Input[previous_output]
  PreviousTransaction = PreviousOutput[hash]
  OutputIndex = PreviousOutput[index]
  Look up the transaction with hash PreviousTransaction
  Output = The output with index OutputIndex in that transaction
  TotalInputValue += Output[value]
Fee = TotalInputValue - TotalOutputValue

Meni Rosenfeld

Posted 2011-12-15T19:04:56.673

Reputation: 18 542

0

you will find more details ( and less technical than pseudocode ) concerning the fee structure on : https://en.bitcoin.it/wiki/Transaction_fees see also https://en.bitcoin.it/wiki/Free_transaction_relay_policy

neofutur

Posted 2011-12-15T19:04:56.673

Reputation: 1 495

Those links have no information at all about what was asked in the question.Meni Rosenfeld 2011-12-17T16:27:59.963

-1

This isn't possible with just the message.

Luke-Jr

Posted 2011-12-15T19:04:56.673

Reputation: 1 064

... because the fee is simply the difference between the sum of the inputs and the sum of the outputs, and the transaction message doesn't specify the value of the inputs. It only provides hashes and output numbers of the transactions which provide the inputs, and so we need access to those transaction messages too. Is that what you meant?Chris Moore 2012-03-07T04:06:07.407