Solidity |松露| Web3 |气体限制

时间:2018-05-27 04:02:18

标签: mocha solidity web3 truffle

我正在尝试使用以下代码在rinkeby测试网上部署联系人:

    const result = await new web3.eth.Contract(JSON.parse(interface))
        .deploy({data: bytecode, arguments: [100, accounts[0]]})
        .send({gas: 1000000, from: accounts[0]});

Attempting to deploy from acount  0xBE80D3f83530f2Ed1214BE5a7434E0cd32177047
(node:3862) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: The contract code couldn't be stored, please check your gas limit.

When I increase the gas limit to 10000000
I get below error. Not able to understand what is wrong with the deployment

Attempting to deploy from acount  0xBE80D3f83530f2Ed1214BE5a7434E0cd32177047
(node:3870) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: exceeds block gas limit

1 个答案:

答案 0 :(得分:0)

你超过了气体限制。您可能在构造函数上做了太多工作,或者您只是发送了一个太低的气体限制。

Rinkeby气体限制在7.4M左右,因此您可以尝试将气体从1M增加到~7.4M。

如果您的合同很大,您可以将其拆分为多个合同,或者正如我之前所说的那样减少在构造函数上完成的工作。