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

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.