<p>Both &quot;1LoVG..&quot; and the other one are valid legacy (1...) addresses made using the same private key. They are different since one of them uses the <strong>compressed public key</strong> (you might want to look this up) while 1GAehh7 uses the uncompressed public key. Always use the same compress-format for an address, and it's advisable to create new addresses in compressed format since it saves bytes and transaction fees.</p>
<p>To make the uncompressed-public-keyed address (compressed is the default in BitcoinJ):</p>
<pre><code>ECKey key = ECKey.fromPrivate(privkey);
key = key.decompress();
String address = LegacyAddress.fromKey(params, key).toString();
</code></pre>

CC BY-SA 4.0
2020-12-20T15:08:28.630Z
2020-12-20T15:08:28.630Z
MCCCS
<p>From <a href="https://en.bitcoin.it/wiki/Wallet_import_format" rel="nofollow noreferrer">the steps in the wiki</a>, take this example private key:</p>
<pre><code>0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
</code></pre>
<p>When I import this into Electrum, I find these values:</p>
<p>Address:</p>
<pre><code>1GAehh7TsJAHuUAeKZcXf5CnwuGuGgyX2S
</code></pre>
<p>Public Key:</p>
<pre><code>04d0de0aaeaefad02b8bdc8a01a1b8b11c696bd3d66a2c5f10780d95b7df42645cd85228a6fb29940e858e7e55842ae2bd115d1ed7cc0e82d934e929c97648cb0a
</code></pre>
<p>How can I determine the address from the key (without using Electrum)?</p>
<p>I understand that the derivation route is private key -&gt; public key -&gt; address, so I've found a way to generate the public key in Java using <a href="https://bitcoinj.org/" rel="nofollow noreferrer">BitcoinJ</a>:</p>
<pre><code>BigInteger privkey = new BigInteger(&quot;0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D&quot;, 16);
byte[] bytes = org.bitcoinj.core.ECKey.publicKeyFromPrivate(privkey, false);
String publickey = new BigInteger(1, bytes).toString(16);
while(publickey.length() &lt; 130){
    publickey = &quot;0&quot; + publickey;
}
Log.d(&quot;public&quot;,publickey);
</code></pre>
<p>It gives the correct public key as shown above, so I just need to find a way to get the address.</p>
<p>I don't know much about different address formats, but my goal is to use the address to check the balance using some public API like <a href="https://www.blockchain.com/btc/address/1GAehh7TsJAHuUAeKZcXf5CnwuGuGgyX2S" rel="nofollow noreferrer">blockchain.com</a>. I guess this is the P2PKH-type address.</p>
<p>I tried this:</p>
<pre><code>NetworkParameters params = MainNetParams.get();
ECKey key = ECKey.fromPrivate(privkey);
String address = LegacyAddress.fromKey(params, key).toString();
Log.d(&quot;address&quot;,address);
</code></pre>
<p>Which gives me this address:</p>
<pre><code>1LoVGDgRs9hTfTNJNuXKSpywcbdvwRXpmK
</code></pre>
<p>But the address is different.</p>

CC BY-SA 4.0
2020-12-20T13:13:31.203Z
Do you mean 1... address, that is compressed or uncompressed, or a SegWit native (Bech32) address or SegWit nested legacy compatible 3... adress. Or even an m-of-n multisig address? If you just want an address, this should help: https://gobittest.appspot.com/Address The link to the answer is in your question, how can we help? Where are you stuck?
MCCCS
CC BY-SA 4.0
2020-12-20T14:31:58.700Z
@MCCCS I added more details, but I want to do it programatically in Java
Gimme the 411
CC BY-SA 4.0
2020-12-20T14:37:06.373Z
Does this help: https://github.com/bitcoinj/bitcoinj/blob/master/examples/src/main/java/org/bitcoinj/examples/PrivateKeys.java#L58-L62 ?
MCCCS
CC BY-SA 4.0
2020-12-20T14:48:50.823Z
@MCCCS I tried it but it gives a different address with a different balance, so I assume it's an unrelated address. I added my code above
Gimme the 411
<address><api><address-generation><bitcoinj>
How can I determine the address from a private key?
Gimme the 411
# How can I determine the address from a private key?

(Asked by: username_0 on 2020-12-20)

From [the steps in the wiki](https://en.bitcoin.it/wiki/Wallet_import_format), take this example private key:

```
0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D

```

When I import this into Electrum, I find these values:

Address:

```
1GAehh7TsJAHuUAeKZcXf5CnwuGuGgyX2S

```

Public Key:

```
04d0de0aaeaefad02b8bdc8a01a1b8b11c696bd3d66a2c5f10780d95b7df42645cd85228a6fb29940e858e7e55842ae2bd115d1ed7cc0e82d934e929c97648cb0a

```

How can I determine the address from the key (without using Electrum)?

I understand that the derivation route is private key -> public key -> address, so I've found a way to generate the public key in Java using [BitcoinJ](https://bitcoinj.org/):

```
BigInteger privkey = new BigInteger("0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D", 16);
byte[] bytes = org.bitcoinj.core.ECKey.publicKeyFromPrivate(privkey, false);
String publickey = new BigInteger(1, bytes).toString(16);
while(publickey.length() < 130){
    publickey = "0" + publickey;
}
Log.d("public",publickey);

```

It gives the correct public key as shown above, so I just need to find a way to get the address.

I don't know much about different address formats, but my goal is to use the address to check the balance using some public API like [blockchain.com](https://www.blockchain.com/btc/address/1GAehh7TsJAHuUAeKZcXf5CnwuGuGgyX2S). I guess this is the P2PKH-type address.

I tried this:

```
NetworkParameters params = MainNetParams.get();
ECKey key = ECKey.fromPrivate(privkey);
String address = LegacyAddress.fromKey(params, key).toString();
Log.d("address",address);

```

Which gives me this address:

```
1LoVGDgRs9hTfTNJNuXKSpywcbdvwRXpmK

```

But the address is different.

**Tags:** address, api, address-generation, bitcoinj

> **Comments:**
> **username_1**: Do you mean 1... address, that is compressed or uncompressed, or a SegWit native (Bech32) address or SegWit nested legacy compatible 3... adress. Or even an m-of-n multisig address? If you just want an address, this should help: https://gobittest.appspot.com/Address The link to the answer is in your question, how can we help? Where are you stuck?  
> **username_0**: @username_1 I added more details, but I want to do it programatically in Java  
> **username_1**: Does this help: https://github.com/bitcoinj/bitcoinj/blob/master/examples/src/main/java/org/bitcoinj/examples/PrivateKeys.java#L58-L62 ?  
> **username_0**: @username_1 I tried it but it gives a different address with a different balance, so I assume it's an unrelated address. I added my code above  

---

## 1 answers

### Answer by username_1 on 2020-12-20. Score: 4 | Accepted answer

Both "1LoVG.." and the other one are valid legacy (1...) addresses made using the same private key. They are different since one of them uses the **compressed public key** (you might want to look this up) while 1GAehh7 uses the uncompressed public key. Always use the same compress-format for an address, and it's advisable to create new addresses in compressed format since it saves bytes and transaction fees.

To make the uncompressed-public-keyed address (compressed is the default in BitcoinJ):

```
ECKey key = ECKey.fromPrivate(privkey);
key = key.decompress();
String address = LegacyAddress.fromKey(params, key).toString();

```


---

