<p>Sorry I have found the solution. The dumped privkey is not comparable to the address. If I want to use the dumped format, I have to use the class DumpedPrivateKey. </p>

<p>Thanks for the help!</p>

<p>After  Aussie Cryptocurrency's request, I am pointing out the problem in the code.
What I was doing was trying to import the private key of the '<em>from</em>' keypair using bitcoin-cli. However, it is important to know that such operations must be run using DumpedPrivateKey: this class can manage private keys in the format that bitcoin-cli likes, whereas in my previous tests I was trying to import the private key simply Base-58 encoding the private key. The odd thing is that if you do so, the key seems to be imported, but the private key is completely different to the expected one.</p>

<p>Hope this helps.</p>

CC BY-SA 3.0
2014-10-06T01:07:12.690Z
Can you elaborate on your answer above? If you can point out the code that was the issue it'd be a great help for others (possibly me!) in the future
Wizard Of Ozzie
CC BY-SA 3.0
2014-10-05T19:21:10.257Z
2014-10-06T08:35:14.247Z
2014-10-06T08:35:14.247Z
fcracker79
<p>I am quite new to Bitcoin. I am trying to use Bitcoinj with regtest mode.
I have created the following application:</p>

<pre><code>public class TestBitcoinj {
    private final static BigInteger ONE = new BigInteger("12345");
    private final static BigInteger TWO = new BigInteger("67890");

    public static void main(String ... args) throws Exception {
        final ECKey from = new ECKey(ONE);
        final ECKey to = new ECKey(TWO);
        System.out.format("from: %s, to: %s\n", from.toAddress(RegTestParams.get()), to.toAddress(RegTestParams.get()));

        final WalletAppKit kit = new WalletAppKit(RegTestParams.get(), new File("/tmp/bitcoinj"), "mirko_btc") {
            protected void onSetupCompleted() {
                System.out.println("Key chain size: " + wallet().getKeychainSize());
                if (wallet().getKeys().isEmpty()) {
                    wallet().addKey(from);
                }
            }
        };

        kit.setAutoSave(true);
        kit.connectToLocalHost();
        System.out.println("State: " + kit.startAndWait());

        System.out.println("Address: " + kit.wallet().getKeys().get(0).toAddress(RegTestParams.get()));
        System.out.println("Private key: " + kit.wallet().getKeys().get(0).getPrivateKeyEncoded(RegTestParams.get()));
        System.out.println("Balance: " + kit.wallet().getWatchedBalance());
        System.out.println("Done");
        System.out.println("State: " + kit.stopAndWait());

    }
}
</code></pre>

<p>I have started bitcoind with the following:</p>

<pre><code>bitcoind -regtest
</code></pre>

<p>I have generated some blocks just to have some money:</p>

<pre><code>bitcoin-cli -regtest setgenerate true 101
</code></pre>

<p>Then I have run my program just to have the private key, which is:</p>

<pre><code>Chiave privata: cNQM8FUZ9tJeNKNNJPiwHZpWkREqzzk5JhioYJWZaszHa5vgsLct
</code></pre>

<p>Now I import that private key in bitcoind using the following:</p>

<pre><code>bitcoin-cli -regtest importprivkey cNQM8FUZ9tJeNKNNJPiwHZpWkREqzzk5JhioYJWZaszHa5vgsLct mirko4
</code></pre>

<p>Finally, I have noticed that my program dumps the following:</p>

<pre><code>Indirizzo: mrtwCcpmvRYU5wBDaUP8LiaW85nGEkbauM
</code></pre>

<p>whereas if I run the following:</p>

<pre><code>bitcoin-cli -regtest getaccountaddress mirko4
</code></pre>

<p>I get the following address:</p>

<pre><code>mrXizN9m9cyKgvBKqCVzTvMAWJoVgnBBev
</code></pre>

<p>That address is far different from the one I have dumped using Bitcoinj. However, the private key should be the same.</p>

<p>Probably I am missing something, but I can not figure out what.</p>

<p>Thank you very much for your support.</p>

CC BY-SA 3.0
2014-10-05T18:06:29.257Z
Try `dumpprivkey mrtwCcpmvRYU5wBDaUP8LiaW85nGEkbauM` using Bitcoin-cli
Wizard Of Ozzie
CC BY-SA 3.0
2014-10-05T18:58:46.310Z
Hi Aussie,thanks for your response. Yes, the provided private key is cNQM8FUZ9tJeNKNNJPiwHZpWkREqzzk5JhioYJWZaszHa5vgsLct, which is the one I would expect. In addition to that, if I import the same private key multiple times creating different accounts, I have different public keys.
fcracker79
CC BY-SA 3.0
2014-10-05T19:20:17.027Z
Sorry I have found the solution. The dumped format is not comparable to ECKey. If I want to use the dumped format, I have to use the class DumpedPrivateKey. Thanks for the help!
fcracker79
<testnet><bitcoinj>
Key exported from BitcoinJ is different from the key shown by bitcoind
fcracker79
# Key exported from BitcoinJ is different from the key shown by bitcoind

(Asked by: username_0 on 2014-10-05)

I am quite new to Bitcoin. I am trying to use Bitcoinj with regtest mode.
I have created the following application:

```
public class TestBitcoinj {
    private final static BigInteger ONE = new BigInteger("12345");
    private final static BigInteger TWO = new BigInteger("67890");

    public static void main(String ... args) throws Exception {
        final ECKey from = new ECKey(ONE);
        final ECKey to = new ECKey(TWO);
        System.out.format("from: %s, to: %s\n", from.toAddress(RegTestParams.get()), to.toAddress(RegTestParams.get()));

        final WalletAppKit kit = new WalletAppKit(RegTestParams.get(), new File("/tmp/bitcoinj"), "mirko_btc") {
            protected void onSetupCompleted() {
                System.out.println("Key chain size: " + wallet().getKeychainSize());
                if (wallet().getKeys().isEmpty()) {
                    wallet().addKey(from);
                }
            }
        };

        kit.setAutoSave(true);
        kit.connectToLocalHost();
        System.out.println("State: " + kit.startAndWait());

        System.out.println("Address: " + kit.wallet().getKeys().get(0).toAddress(RegTestParams.get()));
        System.out.println("Private key: " + kit.wallet().getKeys().get(0).getPrivateKeyEncoded(RegTestParams.get()));
        System.out.println("Balance: " + kit.wallet().getWatchedBalance());
        System.out.println("Done");
        System.out.println("State: " + kit.stopAndWait());

    }
}

```

I have started bitcoind with the following:

```
bitcoind -regtest

```

I have generated some blocks just to have some money:

```
bitcoin-cli -regtest setgenerate true 101

```

Then I have run my program just to have the private key, which is:

```
Chiave privata: cNQM8FUZ9tJeNKNNJPiwHZpWkREqzzk5JhioYJWZaszHa5vgsLct

```

Now I import that private key in bitcoind using the following:

```
bitcoin-cli -regtest importprivkey cNQM8FUZ9tJeNKNNJPiwHZpWkREqzzk5JhioYJWZaszHa5vgsLct mirko4

```

Finally, I have noticed that my program dumps the following:

```
Indirizzo: mrtwCcpmvRYU5wBDaUP8LiaW85nGEkbauM

```

whereas if I run the following:

```
bitcoin-cli -regtest getaccountaddress mirko4

```

I get the following address:

```
mrXizN9m9cyKgvBKqCVzTvMAWJoVgnBBev

```

That address is far different from the one I have dumped using Bitcoinj. However, the private key should be the same.

Probably I am missing something, but I can not figure out what.

Thank you very much for your support.

**Tags:** testnet, bitcoinj

> **Comments:**
> **username_1**: Try `dumpprivkey mrtwCcpmvRYU5wBDaUP8LiaW85nGEkbauM` using Bitcoin-cli  
> **username_0**: Hi Aussie,thanks for your response. Yes, the provided private key is cNQM8FUZ9tJeNKNNJPiwHZpWkREqzzk5JhioYJWZaszHa5vgsLct, which is the one I would expect. In addition to that, if I import the same private key multiple times creating different accounts, I have different public keys.  
> **username_0**: Sorry I have found the solution. The dumped format is not comparable to ECKey. If I want to use the dumped format, I have to use the class DumpedPrivateKey. Thanks for the help!  

---

## 1 answers

### Answer by username_0 on 2014-10-05. Score: 1

Sorry I have found the solution. The dumped privkey is not comparable to the address. If I want to use the dumped format, I have to use the class DumpedPrivateKey.

Thanks for the help!

After Aussie Cryptocurrency's request, I am pointing out the problem in the code.
What I was doing was trying to import the private key of the '*from*' keypair using bitcoin-cli. However, it is important to know that such operations must be run using DumpedPrivateKey: this class can manage private keys in the format that bitcoin-cli likes, whereas in my previous tests I was trying to import the private key simply Base-58 encoding the private key. The odd thing is that if you do so, the key seems to be imported, but the private key is completely different to the expected one.

Hope this helps.

> **Comments:**
> **username_1**: Can you elaborate on your answer above? If you can point out the code that was the issue it'd be a great help for others (possibly me!) in the future  

---

