0

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.

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++;
        }

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.