首先需要安装geth
以下为代码
private static final String URL = "http://localhost:8000";
public static Web3j initWeb3j() {
return Web3j.build(getService());
}
private static HttpService getService(){
return new HttpService(URL);
}
/**
* 创建账户
* @param pwd
* @throws Exception
*/
public static void createAccount(String pwd) throws Exception {
Bip39Wallet wallet = WalletUtils.generateBip39Wallet(pwd, new File("C:\\Users\\Administrator\\Desktop\\keystore\\"));
Credentials credentials = WalletUtils.loadBip39Credentials(pwd, wallet.getMnemonic());
//钱包地址 0x23f984a40d187d6c97b387b5436492023cceb12c
String address = credentials.getAddress();
System.out.println(address);
//钱包私钥 89662c6e15987af2e26617a004b4b03ad57d477313352437acafdee61fc36660
String privateKey = credentials.getEcKeyPair().getPrivateKey().toString(16);
System.out.print