<p>You can't call it an infinite number of times. In fact, with default settings, the 101st call will fail.</p>

<p>While the private keys that control the bitcoins are encrypted, the addresses corresponding to those keys are not.</p>

CC BY-SA 3.0
2012-12-16T14:50:32.327Z
Fascinating... do you know where it's actually stored?
makerofthings7
CC BY-SA 3.0
2012-12-17T06:47:13.640Z
Somewhere in wallet.dat. Beyond that, I couldn't tell you.
Nick ODell
CC BY-SA 3.0
2012-12-16T07:39:56.137Z
2012-12-16T07:39:56.137Z
Nick ODell
<p>Getnewaddress simply marks a private key in the wallet.dat as being used (or, to be more specific, removes that address from the key pool) and returns that address in the response.</p>

<p>So the private key already exists in wallet.dat prior to the getnewaddress call.</p>

CC BY-SA 3.0
2012-12-16T08:03:30.230Z
2012-12-16T08:03:30.230Z
Stephen Gornick
<p>I'm reading <a href="https://en.bitcoin.it/wiki/Wallet_encryption" rel="nofollow noreferrer">this wiki on wallet encryption</a>  and am confused on how I can call <a href="https://bitcoin.stackexchange.com/q/4095/1878">getnewaddress as described here</a> and where that is being tracked after a restart of bitcoind.</p>

<blockquote>
  <p>When a wallet is encrypted, the passphrase is required to top up the
  keypool, thus, if the passphrase is rarely entered, it is possible
  that keypool might run out. In this case, the default key will be used
  as the target for payouts for mining, and calls to getnewaddress and
  getaccount address will return an error. In order to prevent such
  cases, the keypool is automatically refilled when walletpassphrase is
  called with a correct passphrase and when topupkeypool is called
  (while the wallet is unlocked). Note that the keypool continues to be
  topped up on various occasions when a new key from pool is used and
  the wallet is unlocked (or unencrypted). </p>
  
  <p>When wallet passphrase
  enrcyption becomes enabled, any unused keys from the keypool are
  flushed (marked as used) and new keys protected with encyption are
  added. For this reason, make a new backup of your wallet so that you
  will be able to recover the keys from the new key pool should access
  to your backups be necessary.</p>
</blockquote>

CC BY-SA 3.0
2012-12-16T07:58:43.930Z
The wallet.dat holds all private keys.  The "key pool" is simply a queue for those keys already in the wallet.dat that haven't been issued yet through "getnewaddress" or chosen for use as change in a transaction.
Stephen Gornick
<wallet><bitcoind><private-key><encryption><keypool>
How does an encrypted wallet persist used keys from "getnewaddress" and the keypool after a restart?
makerofthings7
# How does an encrypted wallet persist used keys from "getnewaddress" and the keypool after a restart?

(Asked by: username_0 on 2012-12-16)

I'm reading [this wiki on wallet encryption](https://en.bitcoin.it/wiki/Wallet_encryption) and am confused on how I can call [getnewaddress as described here](https://bitcoin.stackexchange.com/q/4095/1878) and where that is being tracked after a restart of bitcoind.

> When a wallet is encrypted, the passphrase is required to top up the
> keypool, thus, if the passphrase is rarely entered, it is possible
> that keypool might run out. In this case, the default key will be used
> as the target for payouts for mining, and calls to getnewaddress and
> getaccount address will return an error. In order to prevent such
> cases, the keypool is automatically refilled when walletpassphrase is
> called with a correct passphrase and when topupkeypool is called
> (while the wallet is unlocked). Note that the keypool continues to be
> topped up on various occasions when a new key from pool is used and
> the wallet is unlocked (or unencrypted).
>
> When wallet passphrase
> enrcyption becomes enabled, any unused keys from the keypool are
> flushed (marked as used) and new keys protected with encyption are
> added. For this reason, make a new backup of your wallet so that you
> will be able to recover the keys from the new key pool should access
> to your backups be necessary.

**Tags:** wallet, bitcoind, private-key, encryption, keypool

> **Comments:**
> **username_1**: The wallet.dat holds all private keys.  The "key pool" is simply a queue for those keys already in the wallet.dat that haven't been issued yet through "getnewaddress" or chosen for use as change in a transaction.  

---

## 2 answers

### Answer by username_2 on 2012-12-16. Score: 1 | Accepted answer

You can't call it an infinite number of times. In fact, with default settings, the 101st call will fail.

While the private keys that control the bitcoins are encrypted, the addresses corresponding to those keys are not.

> **Comments:**
> **username_0**: Fascinating... do you know where it's actually stored?  
> **username_2**: Somewhere in wallet.dat. Beyond that, I couldn't tell you.  

---

### Answer by username_1 on 2012-12-16. Score: 1

Getnewaddress simply marks a private key in the wallet.dat as being used (or, to be more specific, removes that address from the key pool) and returns that address in the response.

So the private key already exists in wallet.dat prior to the getnewaddress call.


---

