Hello again. I have a few more questions and I apologize in advance if they appear stupid
Well, your wallet holds private keys, the public keys of those private keys are hashed. These hashes are your addresses.
In the past, somebody funded your addresses: somebody else created a transaction, and one or more of the outputs of said transaction were funding an address whose private key belonged to your wallet. You have one or more unspent outputs funding one or more addresses, the sum of the value of these unspent outputs is seen as the balance of your wallet.
When you click "send", you wallet will combine one or more of those unspent outputs with a total value equal or greater to the amount you want to transfer PLUS the mining fee. If the sum of the values of the used unspent outputs is bigger than the amount you want to transfer plus the fee, a change address is used. This change addres also belongs to your wallet, and it's funded with the leftover value.
In the meantime, while selecting unspent outputs to use, and finding out wether a change address is needed, your wallet also calculates the optimal fee. Sometimes you can pick your own fee, sometimes a slider is used, sometimes the fee calculation is hidden altogether, but your wallet calculates the weight of your transaction and adjusts the fee accordingly.
Can we use numbers so I can better understand this?
Let's say someone sent me 0.10, 0.20, 0.30, and 0.40 btc in the past [total unspent output = 1 btc] and I want to send 0.55 to someone else. Assuming my wallet will combine the first three transactions 0.10 + 0.20 + 0.30 = 0.60. The excess balance of 0.05 less the mining fee will go to the change address generated by my wallet. Is this correct?
When selecting unspent outputs to combine, does the wallet follow a method like first in first out? Or is this random?
Why is there a change address?
After the unsigned transaction is created (unspent outputs are used as an input, new unspent outputs are created as output), the transaction is signed with the private key(s) belonging to the addresses whose unspent outputs are being used as an input.
I'm lost here.
Using the example above
"unspent outputs are used as an input" = 0.55 + mining fees?
"new unspent outputs are created as output" = 0.05 less mining fees + 0.40?
The signed transaction is now broadcasted to the nodes. Each node checks if all unspent outputs used as input are available in their utxo db (db with all valid unspent outputs), they also check the signatures. Invalid transactions get rejected, valid ones get broadcasted to other nodes.
How many nodes is 1 signed transaction broadcasted to?
In the end, the transaction ends up in the mempool of about all the nodes of the network. Some of these nodes belong to miners. Miners sort the transactions from highest fee/Wu to lowest fee/Wu. They take the top tx's (untill the block is full), calculate a merkle tree, put the merkle root in the block header they're trying to solve (together with the sha256d hash of the previous block header) and try to find a nonce for which the sha256d of the new header is under the current target.
If they succeed, they found a valid block, and they can broadcast it to the network.
As soon as a signed transaction is broadcasted, the receiver usually sees an incoming, unconfirmed transaction. Once a transaction ended up in a valid block, the receiver will see the transaction is confirmed.
When new blocks get mined on top of the block containing a transaction, the receiver will see +1 confirmation...
I understand most parts here. I will need to read about the merkle tree and root.
As long as a transaction remains unconfirmed, it'll stay in the node's mempool. Each node can truncate their mempool, so if a transaction remains unconfirmed for to long, most nodes will have dropped it from their mempool. This is one of the reasons why it's a bad idear to accept 0 conf transaction.
Does this mean that each node have their own mempool? I was under the impression that there is only one mempool.
when you create and broadcast a transaction it goes to the node(s) that you send it to, then those nodes send it to other nodes until nearly all the network finds out about your transaction (assuming it is a valid transaction and it doesn't violate any of the preference rules set by any of the nodes like the standard rules including but not limited to fee per byte).
Do I get to pick which node to send to? Or do you mean to say the node(s) connected to the wallet I am using?