working with the blockchain: transaction fees & sum(inputs) != sum(outputs) (newbie questions) [combined summary]



Individual post summaries: Click here to read the original discussion on the bitcoin-dev mailing list

Published on: 2014-02-14T23:01:41+00:00


Summary:

Denis Andrejew is seeking information on how to access unspent outputs and calculate the balance for all addresses in a specific block of the blockchain. He is using bitcoind via rpc as his source of information about the blockchain. Mark Friedenbach suggests that bitcoind keeps this information in a special LevelDB database in the chainstate directory, making it easy to iterate over and obtain the list of all unspent outputs.However, Denis clarifies that he needs to be able to get the unspent outputs and calculate the balance for any particular block he is interested in, not just the current state of the blockchain. In response to Wladimir's helpful input, Denis expresses gratitude and ends his message with a quote from Mahatma Gandhi: "Be the change you want to see in the world. "Bitcoin blocks contain a coinbase transaction at the beginning, which is special because it can pay coins to its outputs without having to specify an input. The total value of the outputs of the coinbase transaction cannot exceed the block value plus the fees. This is checked in ConnectBlock in the Bitcoin source code. The coinbase transaction's value is also checked on line 1731. The only transactions in which the sum of the outputs can be larger than the sum of the inputs are the coinbase transactions which cannot have inputs. The outputs from the coinbase transaction can be spent like any other output.The poster, who is new to Bitcoin development, is trying to read the blockchain to find all unspent outputs. They are using bitcoind via rpc as their source of information about the blockchain. However, they are confused about how transaction fees work, especially when there is a gap between the sum of the inputs and the sum of the outputs in a transaction. They understand that this gap is the transaction fee, but they are unsure how the miner can spend it if it is not assigned as an output of any transaction.The poster wonders if there is special code somewhere that keeps track of all the BTC not spent in all the transactions of a block and allows the miner's address to spend it, but they are unclear on the details of how this would work. They are requesting technical explanations of transaction fees and how to find them and account for them in the blockchain. They also ask what other cases might exist where the sum of the input values can be different from the sum of the output values. The only two cases the poster currently understands are "coinbase" transactions that create new coins without inputs, and transaction fees when the sum of the inputs is greater than the sum of the outputs.


Updated on: 2023-08-01T07:39:43.354012+00:00