<p>Since Bitcoin Core 0.13, the wallet uses deterministic key derivation.</p>
<p>That means that the wallet stores a single seed, and uses that to derive keys whenever needed. See BIP32 for details.</p>
<p>This has the advantage that a backup of the wallet lasts forever, at least as no other keys are imported. Since the same seed gives rise to the same keys, an older backup will produce the same keys as the real wallet generated after the backup was made, and thus the same payments will be discovered after restoring the backup.</p>
<p><code>MakeNewKey</code> is for generating a new <strong>random</strong> key. For deriving keys from seeds, see the <code>CExtKey</code> functions in key.cpp.</p>

CC BY-SA 4.0
2021-09-19T12:51:14.587Z
2021-09-19T13:53:50.537Z
2021-09-19T13:53:50.537Z
Pieter Wuille
<p>Hi I'm student studying bitcoin-core.
I tested bitcoin regtest mode, and I want to know when CKey::MakeNewKey() is called.</p>
<p>when I do this,</p>
<p><strong>bitcoin-cli -regtest createwallet &quot;wallet1&quot;</strong></p>
<p>MakeNewKey() function was called, but</p>
<p><strong>bitcoin-cli -regtest getnewaddress</strong> or <strong>bitcoin-cli -regtest -generate 1</strong></p>
<p>didn't call MakeNewKey() and only call  GetPrivKey() and GetPubKey() in key.cpp</p>
<p>and when GetPrivKey() was called, the part of key32 in serialized key doesn't match of wallet's private key</p>
<p>My questions are,</p>
<ol>
<li>Is only one private key of my wallet?</li>
<li>Blocks have their own private keys?</li>
<li>If #2 is right, what file make private key and public key of the block</li>
</ol>

<bitcoin-core><private-key><public-key><ecdsa><secp256k1>
Why MakeNewKey in key.cpp isn't called when getnewaddress or generate
hhhbbb
# Why MakeNewKey in key.cpp isn't called when getnewaddress or generate

(Asked by: username_0 on 2021-09-19)

Hi I'm student studying bitcoin-core.
I tested bitcoin regtest mode, and I want to know when CKey::MakeNewKey() is called.

when I do this,

**bitcoin-cli -regtest createwallet "wallet1"**

MakeNewKey() function was called, but

**bitcoin-cli -regtest getnewaddress** or **bitcoin-cli -regtest -generate 1**

didn't call MakeNewKey() and only call GetPrivKey() and GetPubKey() in key.cpp

and when GetPrivKey() was called, the part of key32 in serialized key doesn't match of wallet's private key

My questions are,

1. Is only one private key of my wallet?
2. Blocks have their own private keys?
3. If #2 is right, what file make private key and public key of the block

**Tags:** bitcoin-core, private-key, public-key, ecdsa, secp256k1


---

## 1 answers

### Answer by username_1 on 2021-09-19. Score: 2 | Accepted answer

Since Bitcoin Core 0.13, the wallet uses deterministic key derivation.

That means that the wallet stores a single seed, and uses that to derive keys whenever needed. See BIP32 for details.

This has the advantage that a backup of the wallet lasts forever, at least as no other keys are imported. Since the same seed gives rise to the same keys, an older backup will produce the same keys as the real wallet generated after the backup was made, and thus the same payments will be discovered after restoring the backup.

`MakeNewKey` is for generating a new **random** key. For deriving keys from seeds, see the `CExtKey` functions in key.cpp.


---

