Bitcoin

Generate HD wallet address in Java using Bitcoinj

Is there a method I can use to get addresses, private and public keys for all types of coins supported by HD Wallet? You can create this correctly for Ethereum as seen at https://iancoleman.io/bip39/.

String seedCode = "elevator dinosaur switch you armor vote black syrup fork onion nurse illegal trim rocket combine";

// BitcoinJ
DeterministicSeed seed = new DeterministicSeed(seedCode, null, "", 1409478661L);
DeterministicKeyChain chain = DeterministicKeyChain.builder().seed(seed).build();
List<ChildNumber> keyPath = HDPath.parsePath("M/44H/0H/0H/0/0");
DeterministicKey key = chain.getKeyByPath(keyPath, true);
BigInteger privKey = key.getPrivKey();

System.out.println("0x" + privKey.toString(16));
System.out.println("0x" + key.getPublicKeyAsHex());
System.out.println("0x" + Keys.getAddress(Sign.publicKeyFromPrivate(privKey)));

I’m not sure how to do the same for Bitcoin or other coins. Are there any other ways to get the public key, private key, and address? I’m currently using bitcoinj and web3j libraries.

Related Articles

Back to top button