<p>Yes, you will want to create a new wallet and specify <code>true</code> for <code>disable_private_keys</code>. It is not necessary to specify <code>blank</code> as <code>disable_private_keys</code> will already ensure that no private keys will be generated or imported and as such, the newly created wallet will be blank anyways.</p>

<p>You can then import xpubs, public keys, and addresses into Bitcoin Core using <code>importmulti</code>. By setting <code>"keypool":true</code> for every public key, the keys will be added to Bitcoin Core's keypool and allow you to use <code>getnewaddress</code> to get addresses. Additionally, for change keys, specifying <code>"internal":true</code> will mark change keys as change and allow you to use <code>getrawchangeaddress</code>, <code>fundrawtransaction</code>, and <code>walletcreatefundedpsbt</code> more easily.</p>

<p>However, be careful when importing an xpub that you use the correct derivation paths. If the child keys that you will eventually be using are derived using hardened derivation, you cannot import an xpub as hardened child keys can only be derived from the master private key. In that case, you will have to import each key by itself, which can also be done using <code>importmulti</code>.</p>

CC BY-SA 4.0
2019-05-10T22:51:45.197Z
2019-05-10T22:51:45.197Z
Ava Chow
<blockquote>
  <p>User has a cold storage wallet. User wants to import their xpub into Bitcoin Core and only use the keys associated with the imported xpub as a watch-only wallet.</p>
</blockquote>

<p>You must pay attention about the <strong>xpub</strong> you are talking about and how <strong>bitcore core</strong> handle HD wallet.<br>
If you already got an xpub, it means it has been <strong>generated</strong> and <strong>derivated</strong> from a mnemonic(most likely seed phrase BIP39) with a <strong>specific path</strong> (BIP44 for xpub -> legacy, BIP49 for ypub -> segwit compatible p2sh(p2wpkh)).<br></p>

<p>If you restore an xpub which follows BIP44 in electrum for instance no worries. However you simply can't do it in bitcoin core as their derivation path are specific to BIP32 if I'm correct (or their own choice see <a href="https://bitcoin.stackexchange.com/questions/78993/default-derivation-paths">list</a>) and not BIP44. It means if you got btcs within the xpub following BIP44 you will not find them in bitcoin core and if you use bitcore core new address from your xpub and import it to another wallet you probably won't detect your btc.</p>

<p>Also note that when talking about extended public key for export/import, by convention it's about an extended public keys <strong>after harden</strong> derivation.</p>

<p>Regarding your initial question, I suggestion to play around rpc and read its <a href="https://bitcoincore.org/en/doc/0.18.0/" rel="nofollow noreferrer">commands</a> as you can definitively do it, but stay aware about wallet interoperability...</p>

CC BY-SA 4.0
2019-05-10T15:02:42.170Z
I understand how to import a BIP84 or BIP44 xpub and derive the keys correctly, my question is how to properly clear the wallet so the keypool does not clash with my imported keys or at least ensure I derive the Cold Storage address on demand. So that when I call `getnewaddress` I will be guaranteed to get one of my cold storage addresses. Its a lot to experiment with and I am building an app so want to make sure I do it 100% correctly. I will edit the original question to clarify.
Fontaine
CC BY-SA 4.0
2019-05-10T17:01:55.537Z
This is not an answer to the question; OP asks about `importmulti` which can (albeit in a roundabout way) import any kind of derivation.
Pieter Wuille
CC BY-SA 4.0
2019-05-11T14:35:46.920Z
Was not aim to solve OP's question, just a little "heads-up" about wallet interoperability.. perhaps I should have simply avoid this ^^
onepix
CC BY-SA 4.0
2019-05-10T13:58:30.710Z
2019-05-10T13:58:30.710Z
onepix
<p>The scenario is this:</p>

<p>User has a cold storage wallet and will import their cold storage xpub into Bitcoin Core using <code>getdescriptorinfo</code> and <code>importmulti</code>. User wants to <em>only</em> use the keys associated with the imported xpub as a watch-only wallet and wants to exclude all existing keys in the wallet so as to avoid getting an address not associated with their xpub when calling <code>getnewaddress</code> or <code>getrawchangeaddress</code>.</p>

<p>Would the best way to go about this be to create a blank wallet first with:</p>

<p><code>createwallet "Cold Storage", disable_private_keys: true, blank: true</code>?</p>

<p>Or is there a simpler way to specify which addresses are generated when calling <code>getnewaddress</code>?</p>

<bitcoin-core><json-rpc><bitcoin-cli>
What is the best way to create a wallet with a blank keypool then add keys to it?
Fontaine
# What is the best way to create a wallet with a blank keypool then add keys to it?

(Asked by: username_0 on 2019-05-09)

The scenario is this:

User has a cold storage wallet and will import their cold storage xpub into Bitcoin Core using `getdescriptorinfo` and `importmulti`. User wants to *only* use the keys associated with the imported xpub as a watch-only wallet and wants to exclude all existing keys in the wallet so as to avoid getting an address not associated with their xpub when calling `getnewaddress` or `getrawchangeaddress`.

Would the best way to go about this be to create a blank wallet first with:

`createwallet "Cold Storage", disable_private_keys: true, blank: true`?

Or is there a simpler way to specify which addresses are generated when calling `getnewaddress`?

**Tags:** bitcoin-core, json-rpc, bitcoin-cli


---

## 2 answers

### Answer by username_1 on 2019-05-10. Score: 2 | Accepted answer

Yes, you will want to create a new wallet and specify `true` for `disable_private_keys`. It is not necessary to specify `blank` as `disable_private_keys` will already ensure that no private keys will be generated or imported and as such, the newly created wallet will be blank anyways.

You can then import xpubs, public keys, and addresses into Bitcoin Core using `importmulti`. By setting `"keypool":true` for every public key, the keys will be added to Bitcoin Core's keypool and allow you to use `getnewaddress` to get addresses. Additionally, for change keys, specifying `"internal":true` will mark change keys as change and allow you to use `getrawchangeaddress`, `fundrawtransaction`, and `walletcreatefundedpsbt` more easily.

However, be careful when importing an xpub that you use the correct derivation paths. If the child keys that you will eventually be using are derived using hardened derivation, you cannot import an xpub as hardened child keys can only be derived from the master private key. In that case, you will have to import each key by itself, which can also be done using `importmulti`.


---

### Answer by username_2 on 2019-05-10. Score: 0

> User has a cold storage wallet. User wants to import their xpub into Bitcoin Core and only use the keys associated with the imported xpub as a watch-only wallet.

You must pay attention about the **xpub** you are talking about and how **bitcore core** handle HD wallet.  
If you already got an xpub, it means it has been **generated** and **derivated** from a mnemonic(most likely seed phrase BIP39) with a **specific path** (BIP44 for xpub -> legacy, BIP49 for ypub -> segwit compatible p2sh(p2wpkh)).

If you restore an xpub which follows BIP44 in electrum for instance no worries. However you simply can't do it in bitcoin core as their derivation path are specific to BIP32 if I'm correct (or their own choice see [list](https://bitcoin.stackexchange.com/questions/78993/default-derivation-paths)) and not BIP44. It means if you got btcs within the xpub following BIP44 you will not find them in bitcoin core and if you use bitcore core new address from your xpub and import it to another wallet you probably won't detect your btc.

Also note that when talking about extended public key for export/import, by convention it's about an extended public keys **after harden** derivation.

Regarding your initial question, I suggestion to play around rpc and read its [commands](https://bitcoincore.org/en/doc/0.18.0/) as you can definitively do it, but stay aware about wallet interoperability...

> **Comments:**
> **username_0**: I understand how to import a BIP84 or BIP44 xpub and derive the keys correctly, my question is how to properly clear the wallet so the keypool does not clash with my imported keys or at least ensure I derive the Cold Storage address on demand. So that when I call `getnewaddress` I will be guaranteed to get one of my cold storage addresses. Its a lot to experiment with and I am building an app so want to make sure I do it 100% correctly. I will edit the original question to clarify.  
> **username_3**: This is not an answer to the question; OP asks about `importmulti` which can (albeit in a roundabout way) import any kind of derivation.  
> **username_2**: Was not aim to solve OP's question, just a little "heads-up" about wallet interoperability.. perhaps I should have simply avoid this ^^  

---

