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

  • 2
    What software? Typically your wallet is responsible for constructing transactions, and you don't do this manually. – Pieter Wuille Jun 29 '17 at 17:38
  • 2
    What 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 Jun 29 '17 at 17:47
  • 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 Jun 29 '17 at 17:49
  • 2
    Bitcoin 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 Jun 29 '17 at 17:50
  • 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 Jun 29 '17 at 17:52
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.

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.

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.

  • 1
    Downvoted. Private keys don't have bitcoins, unspent outputs do. This answer continues the confusion that leads to OP's question. – Pieter Wuille Jun 29 '17 at 20:20
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.

  • Why I got the downvote(s), what should I imporve? Thanks. – Gábor Héja Jun 30 '17 at 13:29
  • 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 Jul 2 '17 at 3:17
  • @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 Jul 3 '17 at 12:08

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.