Bitcoin Forum

Other => Beginners & Help => Topic started by: Bowjob on January 19, 2013, 08:54:50 PM



Title: Questions about wallet.dat
Post by: Bowjob on January 19, 2013, 08:54:50 PM
Suppose you back up your wallet.dat, and someone sends bitcoins to one of your addresses, will that backup be rendered obsolete?


Title: Re: Questions about wallet.dat
Post by: yogi on January 19, 2013, 08:56:34 PM
Suppose you back up your wallet.dat, and someone sends bitcoins to one of your addresses, will that backup be rendered obsolete?

No, transactions are recorded in the blockchain, not your wallet.


Title: Re: Questions about wallet.dat
Post by: Bowjob on January 19, 2013, 08:59:17 PM
Suppose you back up your wallet.dat, and someone sends bitcoins to one of your addresses, will that backup be rendered obsolete?

No, transactions are recorded in the blockchain, not your wallet.

How about lets say I have 80 btc backup, then I spend some of that btc.. backup be obsolete then?


Title: Re: Questions about wallet.dat
Post by: Gabi on January 19, 2013, 09:02:59 PM
Wallet.dat hold the keys. The backup is obsolete only if you have new addresses in the other wallet.dat.


Title: Re: Questions about wallet.dat
Post by: 21after2 on January 19, 2013, 09:04:28 PM
Suppose you back up your wallet.dat, and someone sends bitcoins to one of your addresses, will that backup be rendered obsolete?

No, transactions are recorded in the blockchain, not your wallet.

How about lets say I have 80 btc backup, then I spend some of that btc.. backup be obsolete then?

No, for the same reason as the last answer. Your transactions are recorded in the blockchain online. The wallet file just gives you access to your funds: it does not actually hold the amount of BitCoins. If you made a back up wallet a year ago and opened it today, it would sync with the blockchain to reflect the current amount in the wallet, regardless of how much BTC you had at the time of the back up.


Title: Re: Questions about wallet.dat
Post by: Bowjob on January 19, 2013, 09:08:33 PM
All right thanks. Last question. Suppose I delete the whole Bitcoin program and I reinstall it. All I have to do is replace wallet.dat with my backup wallet.dat and everything is gravy, right?


Title: Re: Questions about wallet.dat
Post by: Gabi on January 19, 2013, 09:12:26 PM
Yeah. Just make sure you never lose the right wallet.dat. Note that when you send coins the change for that transaction is put in a new address, so a backup wallet can get outdated (since it would not have that new address)


Title: Re: Questions about wallet.dat
Post by: DannyHamilton on January 19, 2013, 11:35:57 PM
Whoa!  Hang on!  You are getting some advice that can get you into trouble, since you don't have the full picture.

It is correct that all the transactions (both to you and from you) are stored in the public blockchain that all full nodes have a complete copy of.  So as long as you have the correct private keys in your wallet.dat file, it will sync up no matter how old the wallet.dat file is.

However, what nobody has explained clearly to you yet is that the wallet.dat file has a limited number of private keys in it.

Each of your bitcoin addresses is associated with exactly one private key in your wallet.dat.  However, every time you create a transaction to send bitcoins, your client also may create a special bitcoin address that it keeps hidden from you and sends some of your coins there.  Those coins still show up in your wallet balance because your client stores these hidden addresses and their private keys in your wallet.dat.  This means that even if you only have 5 bitcoin addresses in your "receive coins" tab in the user interface, if you have sent bitcoins 10 times, you probably actually have 15 addresses in your wallet.dat file (1 for each address in "receive coins, AND one for each transaction when you sent coins).

The client file pre-generates 100 addresses along with the associated private keys. So when you request a new address from the client (or when it needs a new address for the "change" in a transaction where you sent bitcoins), rather than generating a new one for you it grabs the next one from this pool of pre-generated addresses and then generates a new one to take its place in the pool.

This means that when you back-up wallet.dat, you are backing up all of the private keys that you are currently using AND the next 100 addresses that the client will use in the future.  If you generate a bunch of new addresses and/or create a bunch of transactions to send bitcoins, you'll need to make sure that you backup the wallet.dat again before you've used up 100 addresses or you could lose your bitcoins permanently.

As an example:

User has Bitcoin-QT client and only has the original address when he starts it up.
User backs up wallet.dat.
User receives 100 BTC in a single transaction output to that address and never receives any other bitcoins to this wallet.
User performs 110 transactions sending 0.01 BTC each time
User's wallet shows a balance of 98.9 BTC
User deletes and re-installs the client, then replaces wallet.dat with the backup.
User waits for the client to sync.
User discovers the wallet shows a balance of 0 BTC, and has permanently lost all access to the 98.9 BTC.

So keep in mind that you will want to have a recent copy of the wallet.dat.  It isn't enough to just have an old copy.  How recent it needs to be depends on how many addresses you generate and how many transactions you send.

Also be aware that when you encrypt your wallet, it tosses out the entire 100 address pool, and generates a new set of 100 addresses.  If you create a backup before encrypting, it won't be good for very long after encrypting.


Title: Re: Questions about wallet.dat
Post by: 21after2 on January 19, 2013, 11:53:42 PM
Whoa!  Hang on!  You are getting some advice that can get you into trouble, since you don't have the full picture.

It is correct that all the transactions (both to you and from you) are stored in the public blockchain that all full nodes have a complete copy of.  So as long as you have the correct private keys in your wallet.dat file, it will sync up no matter how old the wallet.dat file is.

However, what nobody has explained clearly to you yet is that the wallet.dat file has a limited number of private keys in it.

Each of your bitcoin addresses is associated with exactly one private key in your wallet.dat.  However, every time you create a transaction to send bitcoins, your client also may create a special bitcoin address that it keeps hidden from you and sends some of your coins there.  Those coins still show up in your wallet balance because your client stores these hidden addresses and their private keys in your wallet.dat.  This means that even if you only have 5 bitcoin addresses in your "receive coins" tab in the user interface, if you have sent bitcoins 10 times, you probably actually have 15 addresses in your wallet.dat file (1 for each address in "receive coins, AND one for each transaction when you sent coins).

The client file pre-generates 100 addresses along with the associated private keys. So when you request a new address from the client (or when it needs a new address for the "change" in a transaction where you sent bitcoins), rather than generating a new one for you it grabs the next one from this pool of pre-generated addresses and then generates a new one to take its place in the pool.

This means that when you back-up wallet.dat, you are backing up all of the private keys that you are currently using AND the next 100 addresses that the client will use in the future.  If you generate a bunch of new addresses and/or create a bunch of transactions to send bitcoins, you'll need to make sure that you backup the wallet.dat again before you've used up 100 addresses or you could lose your bitcoins permanently.

As an example:

User has Bitcoin-QT client and only has the original address when he starts it up.
User backs up wallet.dat.
User receives 100 BTC in a single transaction output to that address and never receives any other bitcoins to this wallet.
User performs 110 transactions sending 0.01 BTC each time
User's wallet shows a balance of 98.9 BTC
User deletes and re-installs the client, then replaces wallet.dat with the backup.
User waits for the client to sync.
User discovers the wallet shows a balance of 0 BTC, and has permanently lost all access to the 98.9 BTC.

So keep in mind that you will want to have a recent copy of the wallet.dat.  It isn't enough to just have an old copy.  How recent it needs to be depends on how many addresses you generate and how many transactions you send.

Also be aware that when you encrypt your wallet, it tosses out the entire 100 address pool, and generates a new set of 100 addresses.  If you create a backup before encrypting, it won't be good for very long after encrypting.

+1 for an excellent post. I didn't know any of that. So it's wisest to backup a wallet, say, once a week or so to insure that the private keys are up to date?


Title: Re: Questions about wallet.dat
Post by: payb.tc on January 19, 2013, 11:57:58 PM
So it's wisest to backup a wallet, say, once a week or so to insure that the private keys are up to date?

yes, if you do 100 transactions per week.

if you do 100 transactions per year, then back up once per year.

different for everybody.


Title: Re: Questions about wallet.dat
Post by: yogi on January 20, 2013, 07:44:06 PM
If you want a wallet that you only ever have to backup once you should look at using a deterministic wallet. All private keys and addresses are generated from a seed, as long as you have the seed backed up, you can recreate your wallet if it gets deleted.


Title: Re: Questions about wallet.dat
Post by: BC12345 on January 20, 2013, 08:03:26 PM
Another thing that might be good to know (correct me if I'm wrong):

When you encrypt your wallet, the keypool with your spare private keys is flushed and a new set of spare addresses is created.
This means that you should update your backups immediately if you encrypt your wallet, otherwise you might loose some/all of your coins when you send a transaction and try to recover/restore your wallet with your backups.


Title: Re: Questions about wallet.dat
Post by: DannyHamilton on January 20, 2013, 08:23:43 PM
Another thing that might be good to know (correct me if I'm wrong):

When you encrypt your wallet, the keypool with your spare private keys is flushed and a new set of spare addresses is created.
This means that you should update your backups immediately if you encrypt your wallet, otherwise you might loose some/all of your coins when you send a transaction and try to recover/restore your wallet with your backups.

Nope. You're not wrong.

As a matter of fact, this other guy mentioned it a few posts back in this thread:

. . . Also be aware that when you encrypt your wallet, it tosses out the entire 100 address pool, and generates a new set of 100 addresses.  If you create a backup before encrypting, it won't be good for very long after encrypting.


Title: Re: Questions about wallet.dat
Post by: BC12345 on January 20, 2013, 08:26:49 PM
Another thing that might be good to know (correct me if I'm wrong):

When you encrypt your wallet, the keypool with your spare private keys is flushed and a new set of spare addresses is created.
This means that you should update your backups immediately if you encrypt your wallet, otherwise you might loose some/all of your coins when you send a transaction and try to recover/restore your wallet with your backups.

Nope. You're not wrong.

As a matter of fact, this other guy mentioned it a few posts back in this thread:

. . . Also be aware that when you encrypt your wallet, it tosses out the entire 100 address pool, and generates a new set of 100 addresses.  If you create a backup before encrypting, it won't be good for very long after encrypting.

Whoops, sorry...