<p>Error -4 means that you've already added that private key. It might take a while to import because it's rescanning the whole blockchain for transactions involving that address.</p>

CC BY-SA 3.0
2013-05-06T14:30:25.620Z
2013-05-06T14:30:25.620Z
lurf jurv
<p>I recently created a custom Public key (with vanitygen) and i would like to add the corresponding private key to my bitcoin-Qt wallet client.  I have started bitcoin-Qt in server mode using:</p>

<p><code>$ open Bitcoin-Qt.app --args -server</code></p>

<p>And then issued the following commands, yet i cannot seem to successful add the private key, can anyone tell me what i am doing wrong?</p>

<pre><code>$ curl --user bitcoinrpc --data-binary '{"method": "walletlock" }' http://127.0.0.1:8332/
Enter host password for user 'bitcoinrpc':
{"result":null,"error":null,"id":null}

$ curl --user bitcoinrpc --data-binary '{"method": "walletpassphrase", "params": ["************", 120] }' http://127.0.0.1:8332/
Enter host password for user 'bitcoinrpc':
{"result":null,"error":null,"id":null}

$ curl --user bitcoinrpc --data-binary '{"method": "walletpassphrase", "params": ["************", 120] }' http://127.0.0.1:8332/
Enter host password for user 'bitcoinrpc':
{"result":null,"error":{"code":-17,"message":"Error: Wallet is already unlocked."},"id":null}

$ curl --user bitcoinrpc --data-binary '{"method": "importprivkey", "params": ["************", "************"] }' http://127.0.0.1:8332/
Enter host password for user 'bitcoinrpc':
{"result":null,"error":{"code":-4,"message":"Error adding key to wallet"},"id":null}
</code></pre>

<p>So what happens is, when i try to decrypt my wallet it just says 'null' as a response.  At first i thought it wasn't actually decrypting, but if i lock it and then try twice to decrypt it, it tells me "Error: Wallet is already unlocked". </p>

<p>Great! so it is unlocked and we should be able to now add the private key, but i just get error code -4 ? what is error -4 ? how do i make this work??</p>

CC BY-SA 3.0
2013-05-05T22:55:25.253Z
I don't actually know, but I think (not sure, so I won't submit an answer) Error -4 means you've already added that private key.
lurf jurv
CC BY-SA 3.0
2013-05-05T23:25:18.467Z
I think you might be correct.  I deleted my wallet (there was nothing in it anyway, just getting started). and started fresh. I get all the way through these steps but instead of the error -4, now bitcoin-qt just crashes and uses 100% cpu when it try's to add that private key.
Do Not Track Me
CC BY-SA 3.0
2013-05-05T23:28:40.700Z
ah! ok, it doesn't crash, it just hangs for a while, eventually it does insert that key! Sweet.  I think your original answer is correct, you should make it an answer so i can mark you approved. thanks!
Do Not Track Me
CC BY-SA 3.0
2013-05-06T13:28:43.003Z
I too found out that importprivkey takes forever on OSX, around 5 minutes on my MBP.
RotHorseKid
<bitcoin-core><mac><rpc-error-4>
Bitcoin-Qt Command line - adding private key - Mac OSX
Do Not Track Me
# Bitcoin-Qt Command line - adding private key - Mac OSX

(Asked by: username_0 on 2013-05-05)

I recently created a custom Public key (with vanitygen) and i would like to add the corresponding private key to my bitcoin-Qt wallet client. I have started bitcoin-Qt in server mode using:

`$ open Bitcoin-Qt.app --args -server`

And then issued the following commands, yet i cannot seem to successful add the private key, can anyone tell me what i am doing wrong?

```
$ curl --user bitcoinrpc --data-binary '{"method": "walletlock" }' http://127.0.0.1:8332/
Enter host password for user 'bitcoinrpc':
{"result":null,"error":null,"id":null}

$ curl --user bitcoinrpc --data-binary '{"method": "walletpassphrase", "params": ["************", 120] }' http://127.0.0.1:8332/
Enter host password for user 'bitcoinrpc':
{"result":null,"error":null,"id":null}

$ curl --user bitcoinrpc --data-binary '{"method": "walletpassphrase", "params": ["************", 120] }' http://127.0.0.1:8332/
Enter host password for user 'bitcoinrpc':
{"result":null,"error":{"code":-17,"message":"Error: Wallet is already unlocked."},"id":null}

$ curl --user bitcoinrpc --data-binary '{"method": "importprivkey", "params": ["************", "************"] }' http://127.0.0.1:8332/
Enter host password for user 'bitcoinrpc':
{"result":null,"error":{"code":-4,"message":"Error adding key to wallet"},"id":null}

```

So what happens is, when i try to decrypt my wallet it just says 'null' as a response. At first i thought it wasn't actually decrypting, but if i lock it and then try twice to decrypt it, it tells me "Error: Wallet is already unlocked".

Great! so it is unlocked and we should be able to now add the private key, but i just get error code -4 ? what is error -4 ? how do i make this work??

**Tags:** bitcoin-core, mac, rpc-error-4

> **Comments:**
> **username_1**: I don't actually know, but I think (not sure, so I won't submit an answer) Error -4 means you've already added that private key.  
> **username_0**: I think you might be correct.  I deleted my wallet (there was nothing in it anyway, just getting started). and started fresh. I get all the way through these steps but instead of the error -4, now bitcoin-qt just crashes and uses 100% cpu when it try's to add that private key.  
> **username_0**: ah! ok, it doesn't crash, it just hangs for a while, eventually it does insert that key! Sweet.  I think your original answer is correct, you should make it an answer so i can mark you approved. thanks!  
> **username_2**: I too found out that importprivkey takes forever on OSX, around 5 minutes on my MBP.  

---

## 1 answers

### Answer by username_1 on 2013-05-06. Score: 2 | Accepted answer

Error -4 means that you've already added that private key. It might take a while to import because it's rescanning the whole blockchain for transactions involving that address.


---

