Why do some transactions have more than one input?

2

I know a normal transaction has 1 input and 2 outputs (if there is change that is the second output).

But what about this scenario? enter image description here

Lets say I'm withdrawing bitcoin from my gemini account and want to calculate the fees. How would I even know if it's 7 addresses sending (which would make the byte size of the transaction larger = higher miner fees) or just 1 address sending?

To further elaborate on test-net here is our system with withdrawing btc to another wallet: https://test-insight.bitpay.com/tx/8bc3db6a4a119e369752a52f0be39ae3a4d579adcdc49e9d92429b920000f934 https://test-insight.bitpay.com/tx/553a27e38a73ed90c792b70add3c3f894e94955440205917ee754787c17ea62b https://test-insight.bitpay.com/tx/cecf112c7e3494826b165f4bcbeca9ef20cc800dce3d433c04b070e4fbc1da81

Here is when I deposited back into our wallet (from copay wallet that supports test net): https://test-insight.bitpay.com/tx/5871e5957ef6ec67a336de01e6f3e4f6f4cffd9986d2f5db181fdcbf6b00d1e0

Marc Alexander

Posted 2017-06-29T17:33:07.780

Reputation: 531

2What software? Typically your wallet is responsible for constructing transactions, and you don't do this manually.Pieter Wuille 2017-06-29T17:38:35.503

2What about it? What is your question? It's perfectly possible, a transaction is allowed to have an arbitrary number of inputs and outputs.Nate Eldredge 2017-06-29T17:47:13.343

A case scenario of how this would happen. How would one transaction do this? Is it kind of like 7 people sending money to two people (but one if the other is change). Or..? Are all those 7 outputs from one node / wallet that has different addresses?Marc Alexander 2017-06-29T17:49:43.800

2Bitcoin transactions don't send from/to addresses. They spend coins integrally and produce new ones. Is there are reference question/answer to explain this?Pieter Wuille 2017-06-29T17:50:55.070

Lets say I'm withdrawing bitcoin from my gemini account and want to calculate the fees. How would I even know if its 7 addresses sending (which would make the byte size of the transaction larger = higher miner fees) or just 1 address sending?Marc Alexander 2017-06-29T17:52:43.800

@MarcAlexander, that would be up to the software that is constructing the transaction. Gemini may allow you to customize and lower the fee...or it may not. If Gemini is constructing the transaction, then you will have to ask Gemini how they do it.Jestin 2017-07-03T14:57:39.007

@MarcAlexander: I've edited your title and retagged your question to better represent what you're actually asking about. Please feel free to revert or further edit your question if you feel that I didn't quite get it right.Murch 2017-07-06T17:34:56.593

Answers

5

What might be confusing you, and which is a common misconception, is that the addresses themselves somehow "hold" the bitcoin balances, and gain and lose the coins via transactions. In fact all the blockchain does is link up previous outputs to new inputs, and the keys make sure only the correct person is allowed to send the coins.

Your balance is just the sum of the total unspent outputs and if you want to send a certain amount to someone, you end up creating a transaction which uses, as input, enough unspent outputs to give the right amount of coins. So if you have a few different smaller unspent outputs, and want to send a large amount, the transaction will end up using multiple of the smaller outputs as input. Because inputs and outputs are used as wholes - they can't be split up as such - you then usually receive a bit of change based on how much the total inputs sum up to, and how much you intended to send.

Of course, most of this is worked out by your wallet client or website which you use, so as an average user you wouldn't normally know in advance how many "addresses" are going to be involved with a specific transaction. The program will just select enough unspent outputs which you hold the keys to, and use them to create the transaction. Hopefully that answers your question to some degree.

MeshCollider

Posted 2017-06-29T17:33:07.780

Reputation: 8 735

1

Value in Bitcoin is not stored in "balances" but rather in unspent transaction outputs. UTXO behave like cheques, you get one each time you receive money, each is exactly for the amount that was signed over, and you can only spend from it once, in full.

When you create a transaction, your software will search a set of UTXO that can fund your transaction. This can be any number of inputs from one to all of your wallet's UTXO.

Murch

Posted 2017-06-29T17:33:07.780

Reputation: 41 609

0

Someone has 7 private keys in their wallet, but none of the private keys have enough unspent outputs for a payment of ~ 2.16 BTC, so the wallet software combines the private keys (and the unspent outputs) to make a 2.16 BTC transaction.

MCCCS

Posted 2017-06-29T17:33:07.780

Reputation: 5 827

1Downvoted. Private keys don't have bitcoins, unspent outputs do. This answer continues the confusion that leads to OP's question.Pieter Wuille 2017-06-29T20:20:45.843

0

Starting from a little far away, the coins are transferred to the Bitcoin Addresses, which are really hashes of public keys. They can be spent using their respective private keys (which is used to generate the public key and the public key hash) which is stored in the Wallet.

Your balance is the sum of unspent transaction outputs (UTXOs) on your Addresses. You can check them manually: in the Bitcoin Core client go to Help > Debug > Console, to check Addresses type listaccounts, to check UTXOs type listunspent or listaddressgroupings.

When you want to send coins to an Address your Bitcoin software goes trough all your unspent transaction outputs and tries to find the best combination to fill that amount (including transaction fee) using as few as possible. In the simplest case one UTXO has enough coin so only that will be used, in other cases more will be combined.

This is the "in" part of the transaction.

After this the Bitcoin software will add the "out" part where the destination Address (or Addresses) you supplied will be present with the amount(s). As a UTXO can only be used up once, all of it must be transferred. From the rest the transaction fee will be paid and the rest is the change, that will be sent back to a newly generated Address of yours (and this will increase the "fragmentation" of your Wallet). The change appears as well in the "out" part (so it will increase the size of the transaction and therefore the fee), while the transaction fee will be left in the transaction with no output.

After this the Bitcoin software will calculate the transaction fee required based on the setting you use (fee amount/byte), update the appropriate amounts (transaciton fee and change) and the transaction is ready to be sent.

Gábor Héja

Posted 2017-06-29T17:33:07.780

Reputation: 269

Why I got the downvote(s), what should I imporve? Thanks.Gábor Héja 2017-06-30T13:29:56.707

Addresses do not have "balances", they have unspent transaction outputs associated with them. There can be multiple UTXO associated with the same address at the same time or at different times. Thus, your answer should read UTXO at various points where you use address, and it doesn't describe the input selection correctly.Murch 2017-07-02T03:17:01.860

@Murch, thanks for the correction, I did some more research and updated the answer (I hope I understood it well this time).Gábor Héja 2017-07-03T12:08:46.307