<p>Apparently to get the RPC command <code>removeprivkey</code> you'll need a build of the Bitcoin client which includes pull #220 (which has been merged into main).  The latest version (currently <a href="https://bitcoin.org/en/download" rel="nofollow">v0.12.1</a>) contains this feature.</p>

<p>Here are the instructions to do that:</p>

<p>Step 1. Back up your wallet.  You are performing wallet surgery here, ... and doing things you might not have intended.</p>

<p>Run Bitcoin as a server, e.g.,</p>

<blockquote>
  <p>$ ./bitcoin-qt -server</p>
</blockquote>

<p>Then </p>

<p>If you've encrypted your wallet you'll need to open it for RPC</p>

<blockquote>
  <p>$ ./bitcoind walletpassphrase [passphrase] 1000</p>
</blockquote>

<p>Then</p>

<blockquote>
  <p>$ ./bitcoind dumpprivkey [bitcoin address]</p>
</blockquote>

<p>Then copy and paste the private key it provides.
Then</p>

<blockquote>
  <p>$ ./bitcoind removeprivkey [bitcoin private key]</p>
</blockquote>

<p>Then close bitcoin-qt.</p>

<p>After that</p>

<blockquote>
  <p>$ ./bitcoind -rescan</p>
</blockquote>

CC BY-SA 3.0
2012-05-14T20:41:23.290Z
I don't understand.  I'm not familiar with the 'removeprivkey' command, but it sounds like it might remove a private key from the wallet.  Wouldn't this cause funds to be lost?  Maybe you missed a step where you add the private key back in again?
Chris Moore
CC BY-SA 3.0
2012-05-17T23:57:39.480Z
I added a step to make a backup first.  Maybe I'm wrong on this, I saw this method described as to how to get the client to not show the 0/unconfirmed transaction.  I'm assuming this masks the problem as if the key isn't in the wallet, then the transaction won't show?  If you import the key right back in, I don't know if that causes the 0/unconfirmed to reappear or not.
Stephen Gornick
CC BY-SA 3.0
2012-08-15T05:23:21.140Z
I agree with Chris that there seems to be a step missing to import the private key back in again. There appear to be instructions here: https://en.bitcoin.it/wiki/How_to_import_private_keys
Highly Irregular
CC BY-SA 3.0
2012-09-17T21:47:13.927Z
Oh, you can run Bitcoin as a server? Cool... I wonder what that offers me...
makerofthings7
CC BY-SA 3.0
2012-05-13T23:58:33.650Z
2016-08-19T14:12:01.970Z
2016-08-19T14:12:01.970Z
Stephen Gornick
<p>The problem is that the Bitcoin wallet implementation is written with the assumption that the transactions it created itself are always valid. If they do not get confirmed, it simply keeps trying to submit then to the network until they get confirmed.</p>

<p>However, since the introduction of dumpprivkey and wallet tools, it's easy enough to create other wallets with the ability to spend from the same key, resulting in potential double spends.</p>

<p>The current best solution is removing the double transaction from the wallet (maybe via a wallet tool, or by dumping the bdb file, removing the transaction line, and importing it again). On a slightly longer term, we plan to make wallets detect transactions that conflict with the block chain, and consider them rejected.</p>

CC BY-SA 3.0
2012-05-17T09:50:01.160Z
2012-05-17T09:50:01.160Z
Pieter Wuille
<p>You could simply send your coins to a new wallet and abandon this one which now has a perennial 0/unconfirmed transaction in it.</p>

<p>[Edit: Though there still could be some funds locked up due to the double spend. </p>

<p>PyWallet can be used to remove all transactions and then rescan, which would cause any funds that might have been locked up in th eunconfirmed transactions to reappear and be available for spending.]</p>

CC BY-SA 3.0
2012-05-14T07:23:53.020Z
Uh? He said the problem was that those coins were marked as spent.
o0'.
CC BY-SA 3.0
2012-05-18T00:23:55.873Z
That shows how to abandon the wallet and to take along any remaining balance that exists.  Double spends don't just happen, you've had to do something wrong (like multiple copies of the wallet running simultaneously, spending the same coins at the same time).  Bitcoin does not yet have a method to recover from this.  Abandoning a wallet showing a double spend by forwarding the funds to a new wallet is still possible and resolves the issue.
Stephen Gornick
CC BY-SA 3.0
2012-05-14T00:10:08.783Z
2012-09-09T19:04:18.867Z
2012-09-09T19:04:18.867Z
Stephen Gornick
<p>Came across an issue where I was given the message:</p>

<p>"Error: The transaction was rejected.  This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."</p>

<p>It appears that the 2nd amount was deducted from my total balance even though it still sits at 0/unconfirmed status days later even though the unconfirmed transaction has disappeared from the blockchain.</p>

<p>Any suggestions?  I've also installed Python and tried running a script provided by someone else (within Windows 7) and cannot seem to get the script to run properly.</p>

<p>Any help is greatly appreciated.</p>

CC BY-SA 3.0
2012-05-13T22:40:42.780Z
At some point this will be something that can be handled by the client.  Currently, the only method to purge that double spend is a manual process.
Stephen Gornick
<wallet><doublespend>
What is the best way to recover from an accidental double-spend?
Dave
# What is the best way to recover from an accidental double-spend?

(Asked by: username_0 on 2012-05-13)

Came across an issue where I was given the message:

"Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."

It appears that the 2nd amount was deducted from my total balance even though it still sits at 0/unconfirmed status days later even though the unconfirmed transaction has disappeared from the blockchain.

Any suggestions? I've also installed Python and tried running a script provided by someone else (within Windows 7) and cannot seem to get the script to run properly.

Any help is greatly appreciated.

**Tags:** wallet, doublespend

> **Comments:**
> **username_1**: At some point this will be something that can be handled by the client.  Currently, the only method to purge that double spend is a manual process.  

---

## 3 answers

### Answer by username_1 on 2012-05-13. Score: 4

Apparently to get the RPC command `removeprivkey` you'll need a build of the Bitcoin client which includes pull #220 (which has been merged into main). The latest version (currently [v0.12.1](https://bitcoin.org/en/download)) contains this feature.

Here are the instructions to do that:

Step 1. Back up your wallet. You are performing wallet surgery here, ... and doing things you might not have intended.

Run Bitcoin as a server, e.g.,

> $ ./bitcoin-qt -server

Then

If you've encrypted your wallet you'll need to open it for RPC

> $ ./bitcoind walletpassphrase [passphrase] 1000

Then

> $ ./bitcoind dumpprivkey [bitcoin address]

Then copy and paste the private key it provides.
Then

> $ ./bitcoind removeprivkey [bitcoin private key]

Then close bitcoin-qt.

After that

> $ ./bitcoind -rescan

> **Comments:**
> **username_2**: I don't understand.  I'm not familiar with the 'removeprivkey' command, but it sounds like it might remove a private key from the wallet.  Wouldn't this cause funds to be lost?  Maybe you missed a step where you add the private key back in again?  
> **username_1**: I added a step to make a backup first.  Maybe I'm wrong on this, I saw this method described as to how to get the client to not show the 0/unconfirmed transaction.  I'm assuming this masks the problem as if the key isn't in the wallet, then the transaction won't show?  If you import the key right back in, I don't know if that causes the 0/unconfirmed to reappear or not.  
> **username_3**: I agree with username_2 that there seems to be a step missing to import the private key back in again. There appear to be instructions here: https://en.bitcoin.it/wiki/How_to_import_private_keys  
> **username_4**: Oh, you can run Bitcoin as a server? Cool... I wonder what that offers me...  

---

### Answer by username_5 on 2012-05-17. Score: 4

The problem is that the Bitcoin wallet implementation is written with the assumption that the transactions it created itself are always valid. If they do not get confirmed, it simply keeps trying to submit then to the network until they get confirmed.

However, since the introduction of dumpprivkey and wallet tools, it's easy enough to create other wallets with the ability to spend from the same key, resulting in potential double spends.

The current best solution is removing the double transaction from the wallet (maybe via a wallet tool, or by dumping the bdb file, removing the transaction line, and importing it again). On a slightly longer term, we plan to make wallets detect transactions that conflict with the block chain, and consider them rejected.


---

### Answer by username_1 on 2012-05-14. Score: 0

You could simply send your coins to a new wallet and abandon this one which now has a perennial 0/unconfirmed transaction in it.

[Edit: Though there still could be some funds locked up due to the double spend.

PyWallet can be used to remove all transactions and then rescan, which would cause any funds that might have been locked up in th eunconfirmed transactions to reappear and be available for spending.]

> **Comments:**
> **username_6**: Uh? He said the problem was that those coins were marked as spent.  
> **username_1**: That shows how to abandon the wallet and to take along any remaining balance that exists.  Double spends don't just happen, you've had to do something wrong (like multiple copies of the wallet running simultaneously, spending the same coins at the same time).  Bitcoin does not yet have a method to recover from this.  Abandoning a wallet showing a double spend by forwarding the funds to a new wallet is still possible and resolves the issue.  

---

