我正在编写一个使用松露和testrpc的概念证明,我不得不花费几个小时来优化代码,以避免出现气体错误。是否有办法绕过此错误或具有非常高的值。我已经尝试过对介电常数设定上限。
介电常数-l 4500000000000
尝试在truffle.js中指定高瓦斯
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*" // Match any network id
,gas: 500000000
}
}不过,在我做测试的时候遇到了汽油不足的情况。
Transaction: 0x0981ab4c4ebdcb851e138d7a18344d256489ef01259f6b714edefdfe23ab824c
Contract created: 0xccb7c4bd42c1e8e809d9f4573a2c2e0590b27b78
Gas usage: 500000000
Block Number: 23
Block Time: Tue Jan 16 2018 08:35:30 GMT-0800 (PST)
Runtime Error: out of gas如果我注释掉5行代码触发事件(因为验证失败),它就不会出现默认的670万气体问题。这里是我的事件,我已经从string切换到了bytes32。
// Used for error handling.
event AnyException(bytes32 m);
event AnyException(bytes32 m1, bytes32 m2);
event AnyException(bytes32 m1, bytes32 m2, bytes32 m3);下面是使用truffle.js中的默认gas注释5行事件之后的成功事务。
Transaction: 0xb9f0f703c7f7e1ae5d51fc8170c00d2f12de146c6c2d5b48a47bd2a1e2a14203
Contract created: 0x87d84cf9d012a181658ce76fa03ab1a7bc0ad538
Gas usage: 6227032
Block Number: 28
Block Time: Tue Jan 16 2018 08:51:03 GMT-0800 (PST)使用5行事件日志,气体使用量怎么能跳得这么高?
发布于 2018-02-04 05:04:18
当我将solc优化器添加到truffle.js并运行
块菌编译-全部
truffle.js
module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// for more about customizing your Truffle configuration!
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*" // Match any network id
}
},
solc: { optimizer: { enabled: true, runs: 200 } }
};发布于 2018-01-16 17:36:22
您在testrpc中设置的气体限制与来自客户的交易的气体限制不同。testrpc配置用于指定块链上的块的限制。但是,创建契约时使用的气体限制将是事务对象中的gas字段中设置的值,或者如果您不提供该值,它将调用estimateGas()。我在testrpc中见过一些情况,其中estimateGas()返回的估计值很差,导致用于该事务的气体限制很低,从而导致气体错误。在发送事务时,请确保在客户端指定了一个气体限制,您应该(希望)看到此错误消失。
发布于 2018-11-17 08:21:15
https://github.com/trufflesuite/ganache-cli/releases/tag/v3.0.0
TestRPC 3.0.0打破改变:交易的默认气体限制现在是90000气体,而不是完整的块状气体限制。
为了避免这些新的气体错误,您现在可以将更高的气体限制作为参数传递给web3:
web3.eth.sendTransaction({..., gas: 3141592}) // choose your own gas limit suitable for you
https://ethereum.stackexchange.com/questions/36508
复制相似问题