我已经用geth建立了一个私有的Ethereum系统。并且正在运行一个使用web3.js文件连接到Ethereum系统的客户端。当我试图发送事务或调用某个合同函数时,我得到了一个错误-
(节点:500) UnhandledPromiseRejectionWarning:错误:返回错误:超过块气体限制
我已经开始使用目标气体限制和创世纪文件使用更高的气体限制的Ethereum节点。
下面是我如何创建ethereum的方法:
geth --datadir /root/.ethereum/geth/datastore/datadir --networkid 15 --rpc --rpcapi web3,eth,personal,miner,net,txpool --rpcaddr <ip> --targetgaslimit=9000000000000 --gasprice '1' console来自genesis.json的片段:
difficulty" : "0xB",
"extraData" : "",
"gasLimit" : "0x2fefd8",正如您所看到的,气体限制被设置为更高的值。现在,我在以太网络上部署了一份智能合同-
pragma solidity ^0.4.13;
contract Simple {
uint public _num = 2;
//contructor
function Simple(uint _inNum) public {
_num = _inNum;
}
function setNum(uint _num2set) public {
_num = _num2set;
}
function getNum() public constant returns (uint) {
return _num;
}
function getArea(uint _side) returns (uint) {
return (_side * _side);
}
function arithmetics(uint _a, uint _b) returns (uint o_sum, uint o_product) {
o_sum = _a + _b;
o_product = _a * _b;
}
function multiply(uint _a, uint _b) returns (uint) {
return _a * _b;
}
}现在,我正在尝试运行一个web3客户端来连接到Ethereum节点。
我已经编写了一些示例应用程序JS代码,它连接到Ethereum节点-
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://172.17.0.8:8545"));现在,我试图通过在Node控制台上运行以下命令来发送事务或调用Ethereum智能契约中的一个函数-
simpleContract.methods.getNum().send({from: '0x41088ec8B25cc67c2558261B62FeD73f8B26ccc2', gasPrice: '0x1', gasLimit: '0x77359400'}).then(console.log)但我总是被超过汽油限值误差。据我所见,这笔交易根本不应超过汽油限额。在启动时的气体限制,以及在命令中都是合理的。当我检查汽油限值时,我得到了一个合理的数字-
web3.eth.getBlock("latest").then(console.log)
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> { difficulty: '635410',
extraData: '0xd88301080f846765746888676f312e31302e31856c696e7578',
gasLimit: 8000000,
gasUsed: 0,下面是我看到的完全错误:
> simpleContract.methods.getNum().send({from: '0x41088ec8B25cc67c2558261B62FeD73f8B26ccc2', gasPrice: '0x1', gasLimit: '0x77359400'}).then(console.log)
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> (node:500) UnhandledPromiseRejectionWarning: Error: Returned error: exceeds block gas limit
at Object.ErrorResponse (/node_modules/web3-core-helpers/src/errors.js:29:16)
at /node_modules/web3-core-requestmanager/src/index.js:140:36
at XMLHttpRequest.request.onreadystatechange (/node_modules/web3-providers-http/src/index.js:91:13)
at XMLHttpRequestEventTarget.dispatchEvent (/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
(node:500) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 62)任何关于问题可能是什么的建议。我甚至试图明确设定天然气和天然气价格: gas:'0x800000',gasPrice:'0x1',gasLimit:'0x77359400',但这也行不通。实际上,如果我将gas设置为较低的值,就会得到一个错误:
(node:500) UnhandledPromiseRejectionWarning: Error: Returned error: insufficient funds for gas * price + value请建议一下。
谢谢!
发布于 2018-10-08 07:45:32
在您的成因文件中,您的气体限制为0x2fefd8。--目标限值为9000000000000,方法调用有gasLimit:'0x77359400‘
重点是:你的目标限制不会立即生效。块体气体的极限将缓慢地向这个值增长。
要检查最后一个区块的气体限制,请调用eth.getBlock("latest").gasLimit
这也是最大的。值可以传递给函数调用,否则事务将被拒绝。
https://ethereum.stackexchange.com/questions/60155
复制相似问题