java - Java 错误中的 gas * price + value 资金不足
问题描述
当我在添加交易时在区块链上部署合同时,它给出了错误......
private static final Web3j web3j = Web3j.build(new HttpService("HTTPS://ropsten.infura.io/v3/d11459c1c17049628f462a1492c7df36"));
private static final Credentials hostCredentials = Credentials.create("666A82FC33F8134577A7BEB1BDEAA689BB72740178727691D63032432B83E0FB");
private static final BigInteger gasLimit = BigInteger.valueOf(4712388L);
private static final BigInteger gasPrice = BigInteger.valueOf(20000000000L);
public String depart_wallet(String code) {
String walletCode = "";
switch(code) {
case "ct_01" :
walletCode = "83E094366642F531189D56DF33AC870DB53AF8C7F7F60A7A8B20CB85BC43A59F";
break;
case "ft_01" :
walletCode = "666A82FC33F8134577A7BEB1BDEAA689BB72740178727691D63032432B83E0FB";
break;
case "ms_01" :
walletCode = "3F0B5C58378DE554534A5A8C630AAC075886E74A6B3229000AE78F4500E153E3";
break;
case "st_01" :
walletCode = "3B69CC479DBAC9B02D2B7C39F7829A2E5DF850203A1766355D854DD89FCC6848";
break;
case "hr_01" :
walletCode = "3F1E2BD4EF8941731D244359F0CDF1EF079E5EAFFD57EA6D31ADDEB55E20D426";
break;
case "mf_01" :
walletCode = "C6FD20908CDC2326A8A5E366228C149FA7632E9C4EF035F5B7EBEE1A04158B7E";
break;
}
return walletCode;
}
我将从网上获取代码。
并通过上述方法发送,获取钱包地址并部署。
public void budgetAdd(HttpServletRequest req, Model model) throws Exception {
String department_code = req.getParameter("dept_code");
String deptWallet = depart_wallet(department_code);
Credentials dept_AccountNumber = Credentials.create(deptWallet);
String contractAddress2 = Materal.deploy(web3j, dept_AccountNumber, gasPrice, gasLimit).send().getContractAddress();
int price = Integer.parseInt(req.getParameter("money"));
BigInteger ethers = null;
if(price < 100000) {
ethers = etherToWei(new BigDecimal(1));
}
else if((100000 < price) && (price < 300000)) {
ethers = etherToWei(new BigDecimal(1.25));
}
else if ((300000 < price) && (price < 500000)) {
ethers = etherToWei(new BigDecimal(1.5));
}
else if ((500000 < price) && (price < 800000)) {
ethers = etherToWei(new BigDecimal(1.8));
}
else if ((800000 < price) && (price < 1000000)) {
ethers = etherToWei(new BigDecimal(2));
}
else {
ethers = etherToWei(new BigDecimal(2.25));
}
byte[] name = stringToBytes32(department_code);
Materal dept = Materal.load(contractAddress2, web3j, hostCredentials, gasPrice, gasLimit);
String hash = dept.buyMaterial(new BigInteger("0"), name, ethers).send().getTransactionHash();
String purpose = req.getParameter("purpose");
HashVO vos = new HashVO();
vos.setDepartment_code(department_code);
vos.setE_subject(purpose);
vos.setE_hashcode(hash);
int insertCnt = dao.insertLog(vos);
if(insertCnt == 1) {
System.out.println("등록되었습니다.");
}
}
我要部署和以太交易完成,插入到 My Oracle。但我的代码无法部署。
也许gasLimit很低?但是,将 GasLimit 更改为 6721975 时出现了同样的错误。
昨天它工作正常,没有错误,但现在它没有工作。你能给我这个错误的答案吗?
解决方案
推荐阅读
- python - 使精灵在点击时消失
- sql - 通过在 Hive/Athena 的 CSV 文件中添加两列来创建外部表
- android - 深度链接在 chrome expo react native 项目中不起作用
- python - 在 MacOS Big Sur 上安装 Python3.4 时出错
- powershell - 创建 NotifyIcon 并使用 powershell 处理单击事件
- typescript - 数组 concat 的返回类型
- android - 如何在 ViewModel 中使用 Strings.xml 而无需在 Android 中使用上下文?
- java - Spring WebClient 下载 PDF 会出现 HTTP 错误
- sql - SQL - 记录案例记录中的状态变化
- javascript - if(id != null) 与 if(!id) 之间的 Javascript 区别