我使用web3j来创建我的以太坊钱包。代码就像下
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();
我可以使用此代码获取我的地址
Credentials credentials = WalletUtils.loadBip39Credentials(password, mnemonic);
String address = credentials.getAddress();
我可以这样导入我的钱包:
Credentials credentials = WalletUtils.loadBip39Credentials(password, mnemonic);
但是以这种方式,我需要密码和助记符,如何通过不带密码的助记符来导入或恢复我的钱包,因为有些钱包应用程序就像metamask或imtoken一样,它们不需要我创建我的钱包和可以重设新密码。
换句话说,恢复或导入钱包只需要助记符,我如何通过web3j来完成
ereryone可以通过web3j告诉我如何做。非常感谢您。
答案 0 :(得分:0)
您可以简单地传递一个空字符串作为密码:
// generate
wallet = WalletUtils.generateBip39Wallet("", tempDir);
// restore using WalletUtils
Credentials credentials = WalletUtils.loadBip39Credentials("", wallet.getMnemonic());
// or using constructor (and empty dummy file)
File tempFile = Files.createTempFile(null, null).toFile();
wallet = new Bip39Wallet(tempFile.getName(), wallet.getMnemonic());