主页 > imtoken转币到交易所 > JAVA使用web3j访问以太坊(一)
JAVA使用web3j访问以太坊(一)
imtoken转币到交易所 2024-01-01 05:08:50
第一步先创建一个maven项目,在项目的pom文件依赖中加入web3j
org.web3j
core
4.2.0
创建钱包
使用org.web3j.crypto.WalletUtils的public static String generateNewWalletFile(String password, File destinationDirectory)方法创建钱包
String wallet = WalletUtils.generateNewWalletFile("123465", new File("D:/"));
generateNewWalletFile 方法输入参数
密码
细绳
钱包密码
目的地目录
文件
创建本地钱包文件的目录
使用全加密
布尔值
是否是轻量钱包 真全款钱包 假轻量钱包
创建钱包伪代码:
//创建钱包
try {
String s = WalletUtils.generateNewWalletFile("123465", new File("D:/"));
} catch (CipherException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
代码执行后,会在文件目录下创建一个json文件。 这是以太坊钱包以太坊加密java,只是一个本地文件。 如果需要操作钱包,需要调用WalletUtils.loadCredentials(String password, File source)生成钱包证书。
钱包证书类org.web3j.crypto.Credentials包含address和ECKeyPair两个属性以太坊加密java,其中address为钱包地址字符串。 ECKeyPair对象包括钱包公钥privateKey和私钥publicKey两个属性,都是BigInteger类型
创建钱包伪代码:
Credentials credentials = WalletUtils.loadCredentials("123456", new File("D:/UTC--2019-09-03T16-31-31.955004500Z--a8d1680c19394f388b9a9bb3e2c4051286ac9554.json"));