<pre><code>$ bitcoin-cli help importmulti
importmulti &quot;requests&quot; ( &quot;options&quot; )

Import addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.
If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned.
Conversely, if all the private keys are provided and the address/script is spendable, the watchonly option must be set to false, or a warning will be returned.

Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls
may report that the imported keys, addresses or scripts exist but related transactions are still missing.
Note: Use &quot;getwalletinfo&quot; to query the scanning progress.

[...SNIP..]

Examples:

&gt; bitcoin-cli importmulti '[{ &quot;scriptPubKey&quot;: { &quot;address&quot;: &quot;&lt;my address&gt;&quot; }, &quot;timestamp&quot;:1455191478 }, { &quot;scriptPubKey&quot;: { &quot;address&quot;: &quot;&lt;my 2nd address&gt;&quot; }, &quot;label&quot;: &quot;example 2&quot;, &quot;timestamp&quot;: 1455191480 }]'
&gt; bitcoin-cli importmulti '[{ &quot;scriptPubKey&quot;: { &quot;address&quot;: &quot;&lt;my address&gt;&quot; }, &quot;timestamp&quot;:1455191478 }]' '{ &quot;rescan&quot;: false}'
</code></pre>
<p>As for your specific import you are passing the <code>keys</code> array (specified as such in the help, see the command above) as an object so <code>bitcoind</code> could not give you a helpful message :</p>
<pre><code>$ bitcoin-cli importmulti '[{ &quot;scriptPubKey&quot;: { &quot;address&quot;: &quot;3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy&quot; }, &quot;timestamp&quot;:&quot;now&quot;, &quot;keys&quot;: [ &quot;Kwngf5FSYmHM5oPHjSoKxtHWUxXiQ5YN5ZR6shmzkYpMMftBh92c&quot; ], &quot;redeemscript&quot;: &quot;00144c88353345f2e03abc8e96b818fd030c3c9f59ab&quot;}]' '{&quot;rescan&quot;: false}'

[
  {
    &quot;success&quot;: true,
  }
]
</code></pre>

CC BY-SA 4.0
2020-05-16T15:29:22.147Z
The result of your import is solvable=false. That's mean the private key have not imported.

But I need to do import specified address with private key.
The result of function `importprivkey` is 3 addresses in wallet. But I need only one that I specified.
kimon
CC BY-SA 4.0
2020-05-16T15:52:50.317Z
I don't understand what you mean ? The error message here is clear : you can't import *already imported* keys.
Also, if you need to import external keys be sure to specify the `redeemScript` field.
Antoine Poinsot
CC BY-SA 4.0
2020-05-16T16:10:10.103Z
derosier, thank you for your attention.
According to the task conditions, there are two wallets. One with the secret key. The second is new. Import must be done in the second (clean) wallet.

How I can get a redeemScript?
kimon
CC BY-SA 4.0
2020-05-17T13:59:00.333Z
@kimon `getaddressinfo` outputs it as the `hex` field (see `bitcoin-cli help getaddressinfo`)
Antoine Poinsot
CC BY-SA 4.0
2020-05-17T16:36:46.907Z
bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy" }, "timestamp":"now", "keys": [ "Kwngf5FSYmHM5oPHjSoKxtHWUxXiQ5YN5ZR6shmzkYpMMftBh92c" ], "redeemscript": "00144c88353345f2e03abc8e96b818fd030c3c9f59ab"}]' '{"rescan": false}'

it works. thank you!
kimon
CC BY-SA 4.0
2020-05-16T14:47:00.557Z
2020-06-16T12:28:36.443Z
2020-06-16T12:28:36.443Z
Antoine Poinsot
<p>Problem. <code>importmulti</code> function has a lot of parameters and they are more difficult to understanding then the parameters of another Bitcoin RPC-API functions. Those who are not profi in modern cryptographic achievements have difficult with understanding how to use <code>importmulti</code> function.</p>

<p>Here is the task that demonstrates the problem.
There is 2 wallets with the Bitcoin Core v.0.19.1:
wallet1 - the wallet with private key for export.
wallet2 - empty wallet into which we need to import the PK+address from wallet1.</p>

<p>So in the wallet1 we have the bitcoin address created by <code>getnewaddress</code>.</p>

<pre><code>[root@wallet1 ~]# bitcoin-cli getaddressinfo 3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy
{
  "address": "3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy",
  "scriptPubKey": "a914d4b1b498c8be8813273937b834be6d9d1f488b9087",
  "ismine": true,
  "solvable": true,
  "desc": "sh(wpkh([675dc179/0'/0'/0']02607cb6c05a575fd040498ec8c44eabfa2a4f0fc320aeacf494a77b3a408d84af))#r6dvu4wk",
  "iswatchonly": false,
  "isscript": true,
  "iswitness": false,
  "script": "witness_v0_keyhash",
  "hex": "00144c88353345f2e03abc8e96b818fd030c3c9f59ab",
  "pubkey": "02607cb6c05a575fd040498ec8c44eabfa2a4f0fc320aeacf494a77b3a408d84af",
  "embedded": {
    "isscript": false,
    "iswitness": true,
    "witness_version": 0,
    "witness_program": "4c88353345f2e03abc8e96b818fd030c3c9f59ab",
    "pubkey": "02607cb6c05a575fd040498ec8c44eabfa2a4f0fc320aeacf494a77b3a408d84af",
    "address": "bc1qfjyr2v697tsr40ywj6up3lgrps7f7kdtvw6mnu",
    "scriptPubKey": "00144c88353345f2e03abc8e96b818fd030c3c9f59ab"
  },
  "label": "",
  "ischange": false,
  "timestamp": 1589545405,
  "hdkeypath": "m/0'/0'/0'",
  "hdseedid": "7cf768d4050dc142a69a149666798cc434045c6c",
  "hdmasterfingerprint": "675dc179",
  "labels": [
    {
      "name": "",
      "purpose": "receive"
    }
  ]
}

[root@wallet1 ~]# bitcoin-cli dumpprivkey 3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy
Kwngf5FSYmHM5oPHjSoKxtHWUxXiQ5YN5ZR6shmzkYpMMftBh92c
</code></pre>

<p>I've tried to import that address to wallet2 but have failed.</p>

<pre><code>[root@wallet2 ~]# bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy" }, "timestamp":"now", "keys": { "Kwngf5FSYmHM5oPHjSoKxtHWUxXiQ5YN5ZR6shmzkYpMMftBh92c":0 }  }]' '{"rescan": false}'

result
[
  {
    "success": false,
    "error": {
      "code": -1,
      "message": "Missing required fields"
    }
  }
]
</code></pre>

<p>What the correct way to import that address using importmulti? Show the example please.</p>

<bitcoin-core><json-rpc><private-key-import><importmulti>
How to import address with private key using importmulti
kimon
# How to import address with private key using importmulti

(Asked by: username_0 on 2020-05-15)

Problem. `importmulti` function has a lot of parameters and they are more difficult to understanding then the parameters of another Bitcoin RPC-API functions. Those who are not profi in modern cryptographic achievements have difficult with understanding how to use `importmulti` function.

Here is the task that demonstrates the problem.
There is 2 wallets with the Bitcoin Core v.0.19.1:
wallet1 - the wallet with private key for export.
wallet2 - empty wallet into which we need to import the PK+address from wallet1.

So in the wallet1 we have the bitcoin address created by `getnewaddress`.

```
[root@wallet1 ~]# bitcoin-cli getaddressinfo 3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy
{
  "address": "3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy",
  "scriptPubKey": "a914d4b1b498c8be8813273937b834be6d9d1f488b9087",
  "ismine": true,
  "solvable": true,
  "desc": "sh(wpkh([675dc179/0'/0'/0']02607cb6c05a575fd040498ec8c44eabfa2a4f0fc320aeacf494a77b3a408d84af))#r6dvu4wk",
  "iswatchonly": false,
  "isscript": true,
  "iswitness": false,
  "script": "witness_v0_keyhash",
  "hex": "00144c88353345f2e03abc8e96b818fd030c3c9f59ab",
  "pubkey": "02607cb6c05a575fd040498ec8c44eabfa2a4f0fc320aeacf494a77b3a408d84af",
  "embedded": {
    "isscript": false,
    "iswitness": true,
    "witness_version": 0,
    "witness_program": "4c88353345f2e03abc8e96b818fd030c3c9f59ab",
    "pubkey": "02607cb6c05a575fd040498ec8c44eabfa2a4f0fc320aeacf494a77b3a408d84af",
    "address": "bc1qfjyr2v697tsr40ywj6up3lgrps7f7kdtvw6mnu",
    "scriptPubKey": "00144c88353345f2e03abc8e96b818fd030c3c9f59ab"
  },
  "label": "",
  "ischange": false,
  "timestamp": 1589545405,
  "hdkeypath": "m/0'/0'/0'",
  "hdseedid": "7cf768d4050dc142a69a149666798cc434045c6c",
  "hdmasterfingerprint": "675dc179",
  "labels": [
    {
      "name": "",
      "purpose": "receive"
    }
  ]
}

[root@wallet1 ~]# bitcoin-cli dumpprivkey 3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy
Kwngf5FSYmHM5oPHjSoKxtHWUxXiQ5YN5ZR6shmzkYpMMftBh92c

```

I've tried to import that address to wallet2 but have failed.

```
[root@wallet2 ~]# bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy" }, "timestamp":"now", "keys": { "Kwngf5FSYmHM5oPHjSoKxtHWUxXiQ5YN5ZR6shmzkYpMMftBh92c":0 }  }]' '{"rescan": false}'

result
[
  {
    "success": false,
    "error": {
      "code": -1,
      "message": "Missing required fields"
    }
  }
]

```

What the correct way to import that address using importmulti? Show the example please.

**Tags:** bitcoin-core, json-rpc, private-key-import, importmulti


---

## 1 answers

### Answer by username_1 on 2020-05-16. Score: 0

```
$ bitcoin-cli help importmulti
importmulti "requests" ( "options" )

Import addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.
If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned.
Conversely, if all the private keys are provided and the address/script is spendable, the watchonly option must be set to false, or a warning will be returned.

Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls
may report that the imported keys, addresses or scripts exist but related transactions are still missing.
Note: Use "getwalletinfo" to query the scanning progress.

[...SNIP..]

Examples:

> bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "<my address>" }, "timestamp":1455191478 }, { "scriptPubKey": { "address": "<my 2nd address>" }, "label": "example 2", "timestamp": 1455191480 }]'
> bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "<my address>" }, "timestamp":1455191478 }]' '{ "rescan": false}'

```

As for your specific import you are passing the `keys` array (specified as such in the help, see the command above) as an object so `bitcoind` could not give you a helpful message :

```
$ bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy" }, "timestamp":"now", "keys": [ "Kwngf5FSYmHM5oPHjSoKxtHWUxXiQ5YN5ZR6shmzkYpMMftBh92c" ], "redeemscript": "00144c88353345f2e03abc8e96b818fd030c3c9f59ab"}]' '{"rescan": false}'

[
  {
    "success": true,
  }
]

```

> **Comments:**
> **username_0**: The result of your import is solvable=false. That's mean the private key have not imported.  But I need to do import specified address with private key. The result of function `importprivkey` is 3 addresses in wallet. But I need only one that I specified.  
> **username_1**: I don't understand what you mean ? The error message here is clear : you can't import *already imported* keys. Also, if you need to import external keys be sure to specify the `redeemScript` field.  
> **username_0**: derosier, thank you for your attention. According to the task conditions, there are two wallets. One with the secret key. The second is new. Import must be done in the second (clean) wallet.  How I can get a redeemScript?  
> **username_1**: @username_0 `getaddressinfo` outputs it as the `hex` field (see `bitcoin-cli help getaddressinfo`)  
> **username_0**: bitcoin-cli importmulti '[{ "scriptPubKey": { "address": "3M5e4QMBUYtpEewwuuoWCArpiM2fT4KEDy" }, "timestamp":"now", "keys": [ "Kwngf5FSYmHM5oPHjSoKxtHWUxXiQ5YN5ZR6shmzkYpMMftBh92c" ], "redeemscript": "00144c88353345f2e03abc8e96b818fd030c3c9f59ab"}]' '{"rescan": false}'  it works. thank you!  

---

