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.
dumpprivkey mrtwCcpmvRYU5wBDaUP8LiaW85nGEkbauM
using Bitcoin-cli