<p>I have write this sample code, hope this helps</p>

<pre><code>public class Main {
    private static NetworkParameters params = NetworkParameters.testNet3();
    public static void main(String...args) {
        String mnemonic = "brisk wood symptom party betray ozone dad super beyond sea memory power pig business extra";
        DeterministicSeed seed = null;
        try {
            seed = new DeterministicSeed(mnemonic, null, "", new Date().getTime());
        } catch (UnreadableWalletException e) {
            e.printStackTrace();
        }
        Wallet wallet = Wallet.fromSeed(params, seed);
        System.out.println(wallet);
        DeterministicKeyChain keyChain = DeterministicKeyChain.builder().seed(seed).build();


        // Derive 100 children, default lookahead is 100
        keyChain.maybeLookAhead();


        // Get M/0H/0/5 key, drive address along with other info for specific path
        DeterministicKey key5 = keyChain.getKeyByPath(ImmutableList.of(ChildNumber.ZERO_HARDENED, ChildNumber.ZERO, new ChildNumber(5)), false);


        System.out.println(key5.toAddress(params).toString());

        // derive 100 addresses along with private key
        System.out.println("_________________________");
        int i = 0;
        while (i &lt; 100) {
            System.out.println(wallet.freshReceiveKey().getPrivateKeyAsHex());
            System.out.println(wallet.freshReceiveAddress());
            i++;
        }

    }
}
</code></pre>

CC BY-SA 4.0
2018-10-03T09:07:36.223Z
2018-10-03T09:07:36.223Z
Zombie
<p>I'm using bitcoinj library for bitcoin.</p>

<p>I want all private keys of all my generated addresses.</p>

<p>How can I achieve that? Please help who knows this answer.</p>

<p>Thanks.</p>

<bitcoinj><android>
Get private-keys from bitcoinj
Bandish
# Get private-keys from bitcoinj

(Asked by: username_0 on 2018-10-03)

I'm using bitcoinj library for bitcoin.

I want all private keys of all my generated addresses.

How can I achieve that? Please help who knows this answer.

Thanks.

**Tags:** bitcoinj, android


---

## 1 answers

### Answer by username_1 on 2018-10-03. Score: 1

I have write this sample code, hope this helps

```
public class Main {
    private static NetworkParameters params = NetworkParameters.testNet3();
    public static void main(String...args) {
        String mnemonic = "brisk wood symptom party betray ozone dad super beyond sea memory power pig business extra";
        DeterministicSeed seed = null;
        try {
            seed = new DeterministicSeed(mnemonic, null, "", new Date().getTime());
        } catch (UnreadableWalletException e) {
            e.printStackTrace();
        }
        Wallet wallet = Wallet.fromSeed(params, seed);
        System.out.println(wallet);
        DeterministicKeyChain keyChain = DeterministicKeyChain.builder().seed(seed).build();

        // Derive 100 children, default lookahead is 100
        keyChain.maybeLookAhead();

        // Get M/0H/0/5 key, drive address along with other info for specific path
        DeterministicKey key5 = keyChain.getKeyByPath(ImmutableList.of(ChildNumber.ZERO_HARDENED, ChildNumber.ZERO, new ChildNumber(5)), false);

        System.out.println(key5.toAddress(params).toString());

        // derive 100 addresses along with private key
        System.out.println("_________________________");
        int i = 0;
        while (i < 100) {
            System.out.println(wallet.freshReceiveKey().getPrivateKeyAsHex());
            System.out.println(wallet.freshReceiveAddress());
            i++;
        }

    }
}

```


---

