创建离线钱包
为了离线脱机交易,你需要有你的钱包文件或与私密钱包/账户相关的公共和私人密钥。 youchain.java能够为你生成一个新的安全的钱包文件,或者你也可以通过私钥来和现有的钱包文件一起工作。
创建新的钱包文件:
String password = "your wallet password";
String keystoreFilePath = "you keystore file path";
String fileName = WalletUtils.generateNewWalletFile(password, new File(keystoreFilePath));
在keystoreFilePath下找到fileName的keystore文件,并妥善保存
从钱包文件加载凭据
Credentials credentials = WalletUtils.loadCredentials(password, keystoreFilePath);
然后这些凭据会被用来签署交易
创建BIP39离线钱包
创建新的钱包文件:
String password = "your wallet password";
Bip39Wallet bip39Wallet = WalletUtils.generateBip39Wallet(password, new File(keystoreFilePath));
String fileName = bip39Wallet.getFilename();
在keystoreFilePath下找到fileName的keystore文件,并妥善保存
获取助记词,请妥善保存助记词(mnemonic):
String mnemonic = bip39Wallet.getMnemonic();
从助记词加载凭据:
Credentials credentials = WalletUtils.loadBip39Credentials(password, mnemonic);
从凭证获取钱包地址、公钥和私钥
String address = credentials.getAddress(); // 钱包地址
BigInteger priKeyBI = credentials.getEcKeyPair().getPrivateKey();
BigInteger pubKeyBI = credentials.getEcKeyPair().getPublicKey();
String privateKey = Numeric.toHexStringWithPrefix(priKeyBI); // 钱包私钥
String publicKey = Numeric.toHexStringWithPrefix(pubKeyBI); // 公钥
请妥善保存私钥信息(privateKey)
通过私钥加载凭证
Credentials credential = Credentials.create(privateKey);