Skip to content

Instantly share code, notes, and snippets.

@jestevez
Created May 18, 2018 10:17
Show Gist options
  • Save jestevez/35ff94bb625225b41de1fa153df3b296 to your computer and use it in GitHub Desktop.
Save jestevez/35ff94bb625225b41de1fa153df3b296 to your computer and use it in GitHub Desktop.
Iancoleman Example
import com.google.common.collect.ImmutableList;
import java.util.Date;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.crypto.ChildNumber;
import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.wallet.DeterministicKeyChain;
import org.bitcoinj.wallet.DeterministicSeed;
import org.bitcoinj.wallet.Wallet;
public class IancolemanExample {
public static void main(String[] args) throws Exception {
System.out.println("IancolemanExample");
final NetworkParameters params = TestNet3Params.get();
String mnemonic = "brisk wood symptom party betray ozone dad super beyond sea memory power pig business extra";
// mnemonic seed
DeterministicSeed seed = new DeterministicSeed(mnemonic, null, "", new Date().getTime());
// new wallet with mnemonic seed
Wallet wallet = Wallet.fromSeed(params, seed);
System.out.println(wallet);
DeterministicKeyChain keyChain = DeterministicKeyChain.builder().seed(seed).build();
// Derive 100 children
keyChain.maybeLookAhead();
int i = 0;
while (i < 100) {
DeterministicKey key5 = keyChain.getKeyByPath(ImmutableList.of(ChildNumber.ZERO_HARDENED, ChildNumber.ZERO, new ChildNumber(i)), false);
System.out.print(key5.getPathAsString() + " ");
System.out.print(key5.toAddress(params).toString() + " ");
System.out.print(key5.getPublicKeyAsHex() + " ");
System.out.print(key5.getPrivateKeyAsWiF(params));
System.out.print("\n");
i++;
}
}
}
@jestevez
Copy link
Author

jestevez commented Feb 6, 2020

public static void main(String[] args) {
	// obscure loan stove case penalty coyote easy fluid employ patrol peanut during
	// embrace now coast
	NetworkParameters params = NetworkParameters.fromID(NetworkParameters.ID_MAINNET);

	String xPub = "xpub6CLGfh7bEzvPxdivQD7RxSXJgk7wGQCSosWSrsiDr2jVimmoHwYU3yTKYEdraX82WHHVcJjk8L7ptb9NCb5bs2XrrnWsLeyr5FscqFqXJct";

	Wallet wallet = Wallet.fromWatchingKeyB58(params, xPub, DeterministicHierarchy.BIP32_STANDARDISATION_TIME_SECS);

	System.out.println("Receiving Address : " + wallet.currentReceiveAddress());

	for (int i = 0; i < 10; i++) {
		System.out.println(i + " : " + wallet.freshReceiveAddress());
	}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment