Web3j error: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.<br> * <strong>Do not modify!</strong><br> * Please use {@link org.web3j.codegen.SolidityFunctionWrapperGenerator} to update. * * <p>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<Uint256> balances(Address param0) { Function function = new Function("balances", Arrays.<Type>asList(param0), Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {})); return executeCallSingleValueReturnAsync(function); } public Future<TransactionReceipt> transfer(Address _to, Uint256 _amount) { Function function = new Function("transfer", Arrays.<Type>asList(_to, _amount), Collections.<TypeReference<?>>emptyList()); return executeTransactionAsync(function); } public static Future<Token> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, BigInteger initialWeiValue) { return deployAsync(Token.class, web3j, credentials, gasPrice, gasLimit, BINARY, "", initialWeiValue); } public static Future<Token> 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;
原文《以太坊常见问题和错误》中的:
http://cw.hubwiz.com/card/c/ethereum-FAQ/1/2/4/
另外推荐一些之前的教程:
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
安装完zsh之后终端显示mvn命令不存在的问题
现象 安装完zsh之后终端显示mvn等命令不存在,现象是新开一个终端,运行mvn命令会显示命令不存在,如报错: zsh: command not found: mvn 但是,在当前终端,运行 source ~/.bash_profile 之后就可以了,我的机器java和mvn的环境变量配置均在~/.bash_profile文件中。 解决 这个问题的原因是zsh的配置文件没有加载~/.bash_profile的配置项,做法如下: vim ~/.zshrc 在文件末尾添加上之前的source ~/.bash_profile保存即可。以后重新打开终端的时候就不会出现mvn命令找不到的问题了。 参考资料 http://ruby-china.org/topics/23158
- 下一篇
合约错误:org.web3j.protocol.exceptions.TransactionException:Error processi...
在执行一个 ERC20 智能合约的transfer调用时发生的org.web3j的一个交易错误: org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction。 Credentials credentials = null; try { this.initWeb3Client(); credentials = WalletUtils.loadCredentials(pwd, path); MyToken mt = MyToken.load(ADDRESS,web3j, credentials, BigInteger.valueOf(20_000_000_000L),BigInteger.valueOf(4_300_000L)); TransactionReceipt tr = oso.transfer(address,value).send(); System.out.println("hash:"+tr.getTransactionHash()); }...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Hadoop3单机部署,实现最简伪集群
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- CentOS8安装Docker,最新的服务器搭配容器使用
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Windows10,CentOS7,CentOS8安装Nodejs环境
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- CentOS7安装Docker,走上虚拟化容器引擎之路