我是使用Java进行智能合约的首次用户,我通常会使用JS。我正在IntelliJ上进行开发,并已设法将Solidity合同编译为Java包装器类。除非我尝试部署合同,否则一切运行正常。它一直说没有足够的资金来进行交易。我使用WalletUtils生成了一个.json文件,我以为这将充当我的钱包,但其中没有提及电量或余额。这些属性也与带有JS的常规genesis.json文件完全不同。我是否认为需要在此文件或天平中添加一些气体?
Web3j web3 = Web3j.build(new HttpService(<Infura endpoint>));
System.out.println("Connected to Ethereum client version: "
+ web3.web3ClientVersion().send().getWeb3ClientVersion());
// This generated the .json file:
WalletUtils.generateNewWalletFile(<password>, new File(""), true);
Credentials credentials =
WalletUtils.loadCredentials(
<password>,
<jsonfile>);
System.out.println("Credentials loaded");
ContractGasProvider contractGasProvider = new DefaultGasProvider();
// Errors at this stage:
RoverMoves contract = RoverMoves.deploy(web3, credentials, contractGasProvider).send();
生成的.json文件如下:
{"address":"c6886a803746be0caee10de1acb165447b64f99e",
"id":"5b3b1932-e4f9-48fd-97bd-0d2845b07147","version":3,
"crypto":{"cipher":"aes-128-ctr",
"ciphertext":"b1d30bf2c5a5a5cb0db43ecb50ff5c0a8f19d47a387d56de0aa4de24cd37cb0b",
"cipherparams":{"iv":"3308e67e4e4ed669608d7cb1b1fe785d"},
"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,
"salt":"c11bc36457e850f545b6120e5b7800e0906c4d3bfdaacb4616bc69c26a2b72fb"},
"mac":"468048c46483da4af7478e2574a8dfce2686fc480e235da47fe8ecdeea426c26"}}