-
Notifications
You must be signed in to change notification settings - Fork 0
Bitcoin basics
If you are new to cryptocurrencies, or never really got a systematic introduction, then this page is for you. These basics apply to Bitcoin, but they also apply to most other coins that work similar to Bitcoin.
Let's start right at the beginning. First, you have a wallet, which is a program that you can use to send and receive money. The first time you open the wallet it will generate many addresses for you, also known as public keys. These addresses are used to receive money. You can give these addresses to anybody, since the only thing someone can do with it is to send money to it. For each public key, there exists one private key in your wallet that can be used to spend money sent to the according public key. Many wallets will generate about 100 addresses internally and display one of them as the default receive address. The other addresses are hidden.
Ok let's assume you have given your address to a friendly donator and you received 1 BTC. Now your wallet shows a balance of 1 BTC. So what happened here? It's simple: The friendly donator made a transaction from his wallet that contained the info to send 1 BTC to your address. So the input of the transaction points to the funds of the sender, and the output is your address. And this transaction was registered on the blockchain, the database of Bitcoin, so that everybody can see it.
Now here is a common misconception: The 1 BTC never "arrives" at your address! That's it. There is no further step. What your wallet program does, in order to to tell you that you have received 1 BTC, is: It reads all of the transactions that have happened on the blockchain and collects those that were sent to one of your addresses! Your balance is simply the sum of the outputs of the transactions that were directed at you that you have not spent yet. These parts of your balance are called Unspent Transaction Outputs (UTXOs). They are the outputs of the transactions that you received to one of your addresses.
Now let's say you want to send 0.3 BTC to your grandma, who is a Bitcoin expert. ;) First, you will have to get an address from your grandma, which you can use as the output for your new transaction. The input must be the unspent 1 BTC that you received earlier. You will cryptographically sign the new transaction using the private key that belongs to your address. But here is a problem: You don't want to send the entire 1 BTC to your grandma. But it still needs to be the input for your transaction, because we only have one UTXO! So what do we do?
The trick here is that we create a transaction that has 2 outputs! One output is the address of your grandma which gets 0.3 BTC. And the other output is one of your own addresses, which gets 0.7 BTC! Since our wallet generated many internal addresses for us, we can just take the next address in the list. Or we could even use the same address again that we used before. We call this address to receive the change (i.e. the money that you get back) a change address. Now we publish this transaction, which has 2 outputs, on the blockchain. After scanning the blockchain, your grandma will find that she has received 0.3 BTC. And your wallet will find a new transaction output for your change address that amounts to 0.7 BTC.
In reality, you also have to include a fee for the miners of Bitcoin, to include your transaction into the blockchain. But that's basically it! It is very important to understand that transactions always consume entire UTXO's and send the rest back to you.
Bitcoin does not deal with the notion of distinct "coins". There are only transactions that have inputs ("where does the money come from?") and outputs ("where does it go to?"). Your wallet just adds them all up, the incoming and the outgoing transactions, to calculate your final balance! It does that for all the addresses that you have in your wallet.
Firstly, it may be distributed to many different addresses, even if you don't know it. Some wallets don't display the addresses they generate for receiving change, they only display the addresses that you generated manually for the purpose of receiving new coins.
And secondly, as explained above, your address never really "stores" the balance. It just means that your wallet can spend transaction outputs that were directed at this address, and use them as a new input.
If you look at the block explorer (a website to inspect the blockchain) and find that your address "contains" a certain amount of BTC, then it just means that the sum of UTXOs for this address amounts to that balance. But it says nothing about the number of these UTXOs, or their size!
Also this means that you should think about addresses as nothing more than a means of receiving payments. It's just a way to get coins into your wallet. They will usually not stay in that address as you continue using the wallet.
Change addresses are often overlooked and are a major source of confusion for newbies. Many Qt wallets will only display the addresses that you created manually (plus a default address) in the receive window, but many more addresses are used by the wallet that are not displayed.
The way how these wallets are meant to be used is to use the receive window to receive payments, and let the wallet manage the storage for you (the association of funds to specific addresses). Many wallets will prefer to use new addresses when applicable to increase your privacy.
If you have carefully read the above text, then you should hopefully be able to answer this for yourself! ;)
No, it was sent to a change address that your wallet created for you. That address might not be displayed in your wallet, but it has always been there. Your total displayed balance should include this amount that was sent back to you.
No! Because once you send money from the according address, it might happen that it gets emptied completely, and the rest is sent to a new change address. Then the balance of your original address, that corresponds to the private key you backed up, will be empty.
Always back up your entire wallet.dat, and do not use the same wallet.dat on multiple devices in parallel! You can also export your private keys as a second security measure, but you shouldn't rely on it.