bitcoinj – can i use one Mnemonic Code to create both(TestNet and MainNet) wallets

Yes. You can create Mainnet and Testnet wallets using one Mnemonic Code.
Here is an example to switch networks.

> java HelloWorld testnet
> mrbZfHK4MuJYEH98w7gENLsrfnY1e4Lq8B

> java HelloWorld mainnet
> 1C5cNEE5YssHTAfXDYhrYRfXonwJe2u1Wf

.

public class HelloWorld {

public static void main(String[] args){

String seedCode = "yard impulse luxury drive today throw farm pepper survey wreck glass federal";
long creationtime = 1409478661L;
DeterministicSeed seed = null;
try {
seed = new DeterministicSeed(seedCode,null,"",creationtime);
} catch (UnreadableWalletException e) {
e.printStackTrace();
}

NetworkParameters params;
if (args[0].equals("testnet")) {
params = TestNet3Params.get();
} else {
params = MainNetParams.get();
}
Wallet wallet = Wallet.fromSeed(params, seed);
Address address = wallet.currentReceiveAddress();
System.out.println(address);

}
}

Source link

Leave a Comment

Your email address will not be published.