I use web3j to create my ethereum wallet.the Code just like down

import org.web3j.crypto.Bip39Wallet;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.ECKeyPair;
import org.web3j.crypto.WalletUtils;

wallet = WalletUtils.generateBip39Wallet(password, new File(keystorePath));
// keystore's file name
String keystoreFileName = wallet.getFilename();
// my mnemonic
String mnemonic = wallet.getMnemonic();

I can use this code get my address

Credentials credentials = WalletUtils.loadBip39Credentials(password, mnemonic);
String address = credentials.getAddress();

I can import my wallet by this:

Credentials credentials = WalletUtils.loadBip39Credentials(password, mnemonic);

but in this way I need password & mnemonic,How I import or recovery my wallet by mnemonic without password,because some wallet app just like metamask or imtoken , they don't need the old password that I create my wallet and the can reset a new password.

In other words,recovery or import the wallet just need mnemonic,how I do it by web3j

enter image description here

Is ereryone can tell me how to do it by web3j.thank u very much.

  • 1
    I think the password is new password as shown in your metamask screen shot
    – Ha ĐANG
    Aug 23 '18 at 3:54
  • yes.Just need mnemonic and u can set a new password.It's meaning that I can reset my wallet just by mnemonic
    – chenhao597
    Aug 23 '18 at 4:02
  • Ah, I mean the password in WalletUtils.loadBip39Credentials(password, mnemonic); also new password, not the current password then you user can input any new password to recover the wallet
    – Ha ĐANG
    Aug 23 '18 at 4:14
  • @HaĐANG right.I want to get it you user can input any new password to recover the wallet but now my user recover the wallet need password
    – chenhao597
    Aug 23 '18 at 8:49

For Bip44 wallets Web3j will use the derivation path m/44/60'/0'/0. The more commonly used path is m/44/60'/0'/0/0 (with an extra /0).

The following code will derive the correct address given a valid mnemonic.

String mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
String password = "";
byte[] seed = MnemonicUtils.generateSeed(mnemonic, password);
Bip32ECKeyPair masterKeypair = Bip32ECKeyPair.generateKeyPair(seed);
final int[] path = {44 | HARDENED_BIT, 60 | HARDENED_BIT, 0 | HARDENED_BIT, 0, 0};
Bip32ECKeyPair childKeypair = Bip32ECKeyPair.deriveKeyPair(masterKeypair, path);
Credentials credential = Credentials.create(childKeypair);


I think that only is password of Metamask, it is not used for wallet encryption. You can recovery wallet with bip39 package:



let seed = await bip39.mnemonicToSeed(mnemonicPhrase, password); //password can null
let HDwallet = await etherHDkey.fromMasterSeed(seed);
let wallet = HDwallet.derivePath(hdPath + "/" + index).getWallet();

You don't need password if you have 12 words simply visit https://iancoleman.io/bip39/ Paste your recovery words it will extract Address with private key


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.