<p>According to the <a href="https://bitcoinj.github.io/javadoc/0.14.2/index.html?org/bitcoinj/wallet/Wallet.html" rel="nofollow noreferrer">documentation</a>:</p>

<blockquote>
  <p>getImportedKeys() returns a list of the non-deterministic keys that
  have been imported into the wallet, or the empty list if none.</p>
</blockquote>

<p>Try to change:</p>

<pre><code>if (wallet().getImportedKeys().size() &lt; 1)
    wallet().importKey(new ECKey());
</code></pre>

<p>to:</p>

<pre><code>if (wallet().getIssuedReceiveKeys().size() &lt; 1)
    wallet().freshReceiveKey();
</code></pre>

<p>To get the first address in your wallet, you can use:</p>

<pre><code>wallet.getIssuedReceiveKeys().get(0).toAddress(TestNet3Params.get()).toBase58().toString();
</code></pre>

CC BY-SA 3.0
2018-04-04T04:39:46.267Z
2018-04-04T04:48:15.433Z
2018-04-04T04:48:15.433Z
Purab
<p>I'm implementing an app using BitcoinJ, but every time I run the code, a new address is created. Is there any way to work with the very first address that was created and stop creating new addresses?</p>

<pre><code>walletAppKit = new WalletAppKit(parameters, walletDir, "my_wallet") {
        @Override
        protected void onSetupCompleted() {

        if (wallet().getImportedKeys().size() &lt; 1) 
           wallet().importKey(new ECKey());
           walletAppKit.peerGroup().setBloomFilterFalsePositiveRate(0.00001);
           setupWalletListeners(wallet());

           for (Address address: wallet().getIssuedReceiveAddresses()){
                Log.d("myLogs", address.toBase58());
           }
        }
    };
walletAppKit.setBlockingStartup(false);
walletAppKit.setUserAgent("RocketWallet", "1.0");
walletAppKit.startAsync();
</code></pre>

<bitcoinj><java><android>
WalletAppKit creates an address every time Bitcoinj gets initialized
sdelvalle57
# WalletAppKit creates an address every time Bitcoinj gets initialized

(Asked by: username_0 on 2017-07-07)

I'm implementing an app using BitcoinJ, but every time I run the code, a new address is created. Is there any way to work with the very first address that was created and stop creating new addresses?

```
walletAppKit = new WalletAppKit(parameters, walletDir, "my_wallet") {
        @Override
        protected void onSetupCompleted() {

        if (wallet().getImportedKeys().size() < 1) 
           wallet().importKey(new ECKey());
           walletAppKit.peerGroup().setBloomFilterFalsePositiveRate(0.00001);
           setupWalletListeners(wallet());

           for (Address address: wallet().getIssuedReceiveAddresses()){
                Log.d("myLogs", address.toBase58());
           }
        }
    };
walletAppKit.setBlockingStartup(false);
walletAppKit.setUserAgent("RocketWallet", "1.0");
walletAppKit.startAsync();

```

**Tags:** bitcoinj, java, android


---

## 1 answers

### Answer by username_1 on 2018-04-04. Score: 1

According to the [documentation](https://bitcoinj.github.io/javadoc/0.14.2/index.html?org/bitcoinj/wallet/Wallet.html):

> getImportedKeys() returns a list of the non-deterministic keys that
> have been imported into the wallet, or the empty list if none.

Try to change:

```
if (wallet().getImportedKeys().size() < 1)
    wallet().importKey(new ECKey());

```

to:

```
if (wallet().getIssuedReceiveKeys().size() < 1)
    wallet().freshReceiveKey();

```

To get the first address in your wallet, you can use:

```
wallet.getIssuedReceiveKeys().get(0).toAddress(TestNet3Params.get()).toBase58().toString();

```


---

