Bitcoin Forum
May 25, 2024, 03:00:25 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Can anybody explain me how inputs and outpouts work?  (Read 106 times)
Andreaslag (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 16


View Profile
March 26, 2021, 11:08:14 AM
 #1

First post here.

I have been studying bitcoin and how it works, and I have read and understood the whitepaper. It is really a unique innovation.

I cannot however wrap my head around inputs and outpouts. What I have currently understood is that a transaction has inputs from 1+ addresses and outpouts to 1+ addresses.
I feel like there is a some kind of "intermediate", which is where the BTC are stored in the transaction (like addresses), and that a bitcoin address consists of transactions.
To send a transaction, you need to specify a parent transaction & address (the input) and a sender address, the output.

Seems like I have got wrong the idea. Can anybody help me out wrap my head around this? I know about bitcoin so you can use terms.
mocacinno
Legendary
*
Offline Offline

Activity: 3402
Merit: 4984


https://merel.mobi => buy facemasks with BTC/LTC


View Profile WWW
March 26, 2021, 11:22:43 AM
Merited by DdmrDdmr (2), vapourminer (1), Jawhead999 (1)
 #2

I'll try to give an ELI5 (very simplified) explanation...

Bitcoin isn't something physical... It isn't stored IN your wallet...
The blockchain is a decentral ledger, it records which unspent outputs are used to fund which address... Your wallet just parses the blockchain and keeps track of which unspent outputs with witch value(s) are funding your address(es).

Let's give a very simple example. I have a wallet containing the private key whose public key hash (address) is 1MyAddress.
The ledger contains a record that says 1MyAddress is funded with output 0 of transaction "transaction1". It does NOT contain a record where i spend this unspent output. Hence, the unspent output sits in the UTXO (the database of all unspent outputs that can, theoretically, be spend)

Since i own the private key belonging to 1MyAddress and the ledger contains above record, i can create a transaction spending the unspent output funding my address. In order to do so, i create a transaction that basically says (in human words):
"I use output 0 of "transaction1" to fund address 1ReceiverAddress with a value of x satoshi's. I sign this transaction with the private key belonging to adress 1Myaddress, which is the address that was funded with output 0 of "transaction1". I call this transaction "transaction2". The input is "output 0 of transaction1", the output is "output 0 of transaction 2".

IF this new transaction gets into a block, all nodes will remove the first unspent output from their UTXO db, and they'll add "output 0 of transaction2" to their UTXO db. The wallet of the person who owns 1ReceiverAddress will parse the blockchain and see a new unspent output funding one of it's addresses, and it'll update the value of the wallet accordingly (and allow the receiver to use the unspent outputs as an input for a new transaction if he/she wishes to do so)

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
20kevin20
Legendary
*
Offline Offline

Activity: 1134
Merit: 1597


View Profile
March 26, 2021, 11:43:50 AM
Last edit: March 26, 2021, 12:16:25 PM by 20kevin20
 #3

You receive 1 BTC from me. Before you received it, it was considered an unspent output sitting in my wallet. When I'm creating the transaction, the 1 BTC now becomes an "input" I'm sending to your address (the output). And until you spend the coin I gave you, it's known as unspent. After you spend it, it becomes spent.

Now say I gave you another 0.5 BTC. You now own two unspent outputs (1 BTC + 0.5 BTC). If you want to move those together to a paper wallet, when you create the transaction what happens is.. the two unspent outputs become your transaction's inputs and the paper wallet becomes the output.

Bitcoins aren't stored in "intermediate addresses" or anything of that sort. They just move from address to address.



You go to a BTC ATM and purchase 1 BTC that is sent to your personal wallet's address. Now, you own 1 BTC which is known to the blockchain as an "unspent output".

Now let's say you want to split your Bitcoins into two: you want to fund a paper wallet with 0.25 BTC and keep the rest in your personal wallet as a change. When you do this, you are first of all spending your first unspent output (the 1 BTC) and you're not only doing that but you're also splitting the output into two: the 0.25 BTC paper wallet funding and the 0.75 BTC that you keep as a change.

When initializing the transaction, you have the initial unspent 1 BTC as the input (think of the input as money you want to spend) and two outputs:
 - 0.25 - going to paper wallet
 - 0.75 - the change

So now, the ledger knows the following:
 - The 1 BTC you bought from the ATM is now spent
 - An address now owns 0.25 BTC, which becomes an unspent output
 - Another address now owns 0.75 BTC, which becomes another unspent output.


Edit: I think something's wrong with this explanation so I'd rather strike it, lol.
ranochigo
Legendary
*
Offline Offline

Activity: 2982
Merit: 4193



View Profile
March 26, 2021, 12:00:14 PM
Merited by vapourminer (1), DdmrDdmr (1)
 #4

Great explanation above. I'll add on slightly.

Addresses are not concepts that exist on a protocol level, they are just better representation for the users using it as it does have error detection included. The output defines the criteria to be able to spend them, for most scenarios it means that only a signature that is signed by specific public key is valid as the public key hash is specified in the output script. In certain cases, this could be spending to P2SH address which would mean that only by fulfilling the criteria needed for that P2SH script then your transaction will be valid.

The blockexplorers that you see actually parses the blockchain and matches the transactions to the address but it doesn't mean that the network functions like this. Bitcoins are not stored in addresses, your wallet simply finds the unspent outputs and the transactions that are relevant to your wallet and displays them to you. This is also why you have to synchronize Bitcoin Core to be able to see your transactions and your address "balance".

Sender address is not specified in the transaction, your transaction contains the ECDSA public key of the relevant address and is also how nodes or anyone else can verify the signature to be correct and that the public key hash also corresponds to the public key hash that was referenced in the previous UTXO. For a P2PKH transaction, the previous TXID is referenced with its index and a signature with the public key.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!