php_version_too_low,以太坊常见问题和错误 / Web3j error:Intrinsic gas too low - 汇智网
我是一个以太坊区块链ethereum blockchain开发新手,我一直尝试执行智能合约使用MetaMask和Remix在Chrome浏览器上。
我现在正在尝试使用web3j开发并通过Java部署相同的以太坊智能合约。
但是当我尝试执行我的智能合约时,得到以下错误:error Intrinsic gas too low
Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.RuntimeException: Error processing transaction request: Intrinsic gas too low
at java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
at java.util.concurrent.CompletableFuture.get(Unknown Source)
at com.solartis.bc.Sample.main(Sample.java:44)
Caused by: java.lang.RuntimeException: Error processing transaction request: Intrinsic gas too low
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:43)
at org.web3j.tx.Contract.lambda$deployAsync$24(Contract.java:288)...
我已经通过几个方法来增加gas的值,但是不管我支付多大的值,我仍然会得到同样的错误。
有没有其他人面临同样的问题,我不知道问题在哪儿。下面附上更多细节:
ContractRunner.java
package com.solartis.bc;
public class ContractRunner {
public static void main(String args[]) throws InterruptedException, ExecutionException, IOException, CipherException, TransactionTimeoutException {
Web3j web3 = Web3j.build(new HttpService("http://xxxxxxx.westus.cloudapp.azure.com:8545/")); // defaults to http://localhost:8545/
Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().sendAsync().get();
String clientVersion = web3ClientVersion.getWeb3ClientVersion();
System.out.println(clientVersion);
Credentials credentials = WalletUtils.loadCredentials("Mxxxxxxxxe", "C:\\Users\\adheep_m\\AppData\\Roaming\\Ethereum\\keystore\\UTC--2017-07-07T13-52-18.006069200Z--3b0d3fa08f0e0b3da8fe1f8ac0e05861bfdada25");
System.out.println(credentials.getAddress());
BigInteger GAS = new BigInteger("30000000");
BigInteger GAS_PRICE = new BigInteger("20");
BigInteger ETH = new BigInteger("1");
//LeisureTravelPolicyHolder contract = LeisureTravelPolicyHolder.deploy(web3,credentials,GAS,GAS_PRICE,ETH,test,test,test,test,test,test,test,test,test).get();
Token con = Token.deploy(web3,credentials,GAS,GAS_PRICE,ETH).get();
System.out.println(con.getContractAddress());
}
}
Token.sol:
pragma solidity ^0.4.0;
contract Token {
mapping (address => uint) public balances;
function Token() {
balances[msg.sender] = 1000000;
}
function transfer(address _to, uint _amount) {
if (balances[msg.sender] < _amount) {
throw;
}
balances[msg.sender] -= _amount;
balances[_to] += _amount;
}
}
Token.java:
package com.solartis.bc;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.Future;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
/**
* Auto generated code.
* Do not modify!
* Please use {@link org.web3j.codegen.SolidityFunctionWrapperGenerator} to update.
*
*
Generated with web3j version 2.2.1.
*/
public final class Token extends Contract {
private static final String BINARY = "6060604052341561000f57600080fd5b5b600160a060020a0333166000908152602081905260409020620f424090555b5b6101678061003f6000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166327e235e38114610048578063a9059cbb14610086575b600080fd5b341561005357600080fd5b61007473ffffffffffffffffffffffffffffffffffffffff600435166100b7565b60405190815260200160405180910390f35b341561009157600080fd5b6100b573ffffffffffffffffffffffffffffffffffffffff600435166024356100c9565b005b60006020819052908152604090205481565b73ffffffffffffffffffffffffffffffffffffffff3316600090815260208190526040902054819010156100fc57600080fd5b73ffffffffffffffffffffffffffffffffffffffff338116600090815260208190526040808220805485900390559184168152208054820190555b50505600a165627a7a7230582081fd33c821a86127abf00c9fafe2e14e4db6279ab9dd788e3ad3597d2280b6cf0029";
private Token(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
private Token(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
public Future balances(Address param0) {
Function function = new Function("balances",
Arrays.asList(param0),
Arrays.>asList(new TypeReference() {}));
return executeCallSingleValueReturnAsync(function);
}
public Future transfer(Address _to, Uint256 _amount) {
Function function = new Function("transfer", Arrays.asList(_to, _amount), Collections.>emptyList());
return executeTransactionAsync(function);
}
public static Future deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) {
return deployAsync(Token.class, web3j, credentials, gasPrice, gasLimit, BINARY, "", initialWeiValue);
}
public static Future deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) {
return deployAsync(Token.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "", initialWeiValue);
}
public static Token load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
return new Token(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
public static Token load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
return new Token(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
}
}
问题原因及解决
问题出现在GAS_PRICE和GAS_LIMIT不合适。Web3j有默认的GAS_PRICE和GAS_LIMIT。以下是更新后的代码:
BigInteger GAS = Contract.GAS_LIMIT;
BigInteger GAS_PRICE = Contract.GAS_PRICE;
Contract.GAS_LIMIT和Contract.GAS_PRICE被启用了,因此,使用下面的常数org.web3j.tx.gas.DefaultGasProvider来代替:
DefaultGasProvider.GAS_PRICE;
DefaultGasProvider.GAS_LIMIT;
php_version_too_low,以太坊常见问题和错误 / Web3j error:Intrinsic gas too low - 汇智网相关推荐
- java.lang.arr_以太坊常见问题和错误 / java.lang.ArrayIndexOutOfBoundsException? - 汇智网...
web3j:智能合约写操作时总是抛出java.lang.ArrayIndexOutOfBoundsException错误,不知道什么问题. 我的代码如下: String hexPrivateKey = ...
- 以太坊中的账户、交易、Gas和区块Gas Limit等基本概念
本篇文章作为科普文章,汇总整理了以太坊中的账户.交易.Gas和区块Gas Limit等相关概念,以便大家在实践中更好的与具体业务相结合. 什么是账户 以太坊账户与我们所知的账户概念有一定相似之处,却又 ...
- java和以太坊交互_java类库web3j开发以太坊智能合约快速入门
web3j简介 web3j是一个轻量级.高度模块化.响应式.类型安全的Java和Android类库提供丰富API,用于处理以太坊智能合约及与以太坊网络上的客户端(节点)进行集成. 可以通过它进行以太坊 ...
- uni-app框架+app端+ethers.js库+以太坊开发+常见错误
uni-app框架常见错误解决方案: app端如果不使用兼容的ethers.js库,uni-app框架会报错: * reportJSException > ...
- Web3j通过合约地址监听transfer事件获取以太坊交易数据
Web3j通过合约地址监听transfer事件获取以太坊交易数据 We3j web3j是一个轻量级的Java库,用于在Ethereum网络上集成客户端(节点). 核心特性 通过Java类型的JSON- ...
- android web3j 代币查询_Android通过web3j以太坊智能合约交互
如果要下载整个以太坊区块链并保持本地节点同步.当区块链占用了我计算机上超过100GB的空间.这在台式计算机上可能有意义,但在移动设备上则不太合理. 解决此限制的一种方法是使用像Infura这样的服务. ...
- java 以太坊 智能合约_web3j教程:java使用web3j开发以太坊智能合约交易
从广义上讲,有web3j支持三种类型的以太坊交易: 1.以太币从一方交易到另一方 2.创建一个智能合约 3.与智能合约交易 为了进行这些交易,必须有以太币(以太坊区块链的代币)存在于交易发生的以太坊账 ...
- web3j的Gradle插件(solidity以太坊智能合约)
web3j Gradle插件是从Solidity智能合约生成web3j Java封装的构建工具.它通过添加可以独立运行的特定任务,顺利地与项目的构建生命周期集成. 插件配置 在开始之前,如果计算机中尚 ...
- java以太坊库web3j的maven插件
web3j maven插件用于基于solidity智能合约文件创建java类. 用法 插件的基本配置将从src/main/resources获取solidity文件,并将java类生成到src/mai ...
最新文章
- 云上人第七代产品简单的代码
- 一种解决 MacBook 里的 App Store 无法登录的问题
- eclipse安装birt插件
- php能不能动态显示html5,php – 是否可以动态生成html5缓存清单?
- linux 命令后面的参数小叙
- 中国营销界:震惊全球的六种“武器”
- 找到MVC框架中前端URL与后端同步的解决方案
- qml demo分析(clocks-时钟)
- JSP教程第1讲笔记
- 为什么要参加PMP考前培训?有什么好处?
- 计算机硬件参数及性能判断,小菜硬件杂谈 如何从显卡型号判断性能
- LINUX基本操作(实验1)
- 直播平台搭建源码,css预加载旋转动画 与 流光字体
- 站群网站八大盈利模式浅析
- 计算机怎黑夜模式么启动,Win10系统电脑夜间模式怎么开启/关闭的方法
- app中的长连接与实现方式
- 浅谈八百呼电销系统的基础功能
- PPT幻灯片放映不显示备注,只让备注显示在自己屏幕上-投影机 设置
- 利用iframe实现局部打印(区域打印)
- 微信生态的优劣,将决定微信电商的未来
热门文章
- MinIO: Console endpoint is listening on a dynamic port , please use --console-address
- MAXIMO学习笔记
- Python字符串日常练习(基础向)
- Android 贝塞尔曲线实战之网易云音乐鲸云特效,2021程序员进阶宝典
- Neo4j Server shutdown initiated by request.解决方案
- 【完整面经含答案】华为校招+阿里巴巴社招,Java开发岗位
- HashSet及LinkedHashSet源码分析(基于JDK1.6)
- 一只青蛙一次可以跳上1级台阶也可以跳上2级求该青蛙跳上一个n级的台阶总共有多少种跳法?
- 变态跳台阶问题:一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法?
- NumPy的实用函数整理之percentile