0

As a little learning/hobby project i'm writing a little c++ program to extract a list of transactions from blockchain.info and show it visually.

I was hoping i could iterate through blocks, taking each TX and then extract into an array a list of transactions. i.e. Block/transactionID/sending_address/amount/receiving_address etc

Ive connected to blockchain.info and can iterate through each block using jsoncpp. But if i look at an example like this:

https://blockchain.info/block-height/100001?format=json

...and specifically transactions like this: https://blockchain.info/rawtx/8131ffb0a2c945ecaf9b9063e59558784f9c3a74741ce6ae2a18d0571dac15bb

Will the sum of inputs always match the sum of outputs? How would i marry up which input sent what amount to each output when there is more than 1 in each?

Many Thanks.

  • Please do not delete questions once they have been answered, as it causes confusion for future readers with the same kind of problems – Raghav Sood May 27 '18 at 22:37
1

nice - but I promise, it will not be a "little" project :-)

Will the sum of inputs always match the sum of outputs?

no! There is a general rule, that whatever is the difference, will be miner fees. To be more precise, the miner is free to take it as fees. So this is a reason why you should have always "return" addresses in your transactions.

How would i marry up which input sent what amount to each output when there is more than 1 in each?

The idea of bitcoin transactions is, that they are not linked directly to addresses, but to previous transactions. And they are not "divisible", but more "additional". I try to explain: funds are transferred from a previous transaction to a new location. Your wallet software might easily handle several addresses. If you send from your wallet to a new target, the wallet might have to take 2 or 3 or 4 previous tx, to send to new address, cause the funds on the single tx where insufficient for the total amount. In this sense, you (your C++ code) can only "match" inputs to outputs (with the derived addresses). Many huge transactions have hundreds of inputs and/or outputs - imagine faucets or exchanges: they create 1 transaction, with many payouts to different owners/users (e.g. https://blockchain.info/de/tx/2062a2717ca2f77c6935ff685d33086aa5db2f554ecd4d5232432cf9cb6a4006).

Taking your example: one can see that 5 inputs were required, to spend 250BTC to 15xif4SjXiFi3NDEsmMZCfTdE9jvvVQrjU and 1mio Satoshis to 1NkKLMgbSjXrT7oHagnGmYFhXAWXjJsKCj. That's nearly all you can say, what happened in this tx. The analogy from Andreas (and his book "Mastering Bitcoin", online readable, highly recommended) is FIAT money. You have maybe 10, 20 and 50 Euro bills in your wallet, but don't know from whom. Now you want to pay 35 Euros. So you give 50, and receive maybe 3 times 5 Euros as change. You still don't know, from whom they came, but just the amount. These "three times 5 Euros" could then be used as 3 inputs for a new 15 Euros transaction.

  • (1) Not an additional transaction, but an additional output from the same transaction. (2) Yes. (3) Yes, when an output is listed as the input of another transaction, that output is marked as spent, and any further transaction listing it as an input will be considered invalid. So those outputs are shown as "spent" because there has been another transaction showing it as an input. In the example you linked, output 0 of this transaction was spent as input 4 of transaction 2b62b3c433bda7a845466e4ec100cad9347f8c039bcc6d78d56f52d8ecb7671e. – Nate Eldredge Jan 15 '18 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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