我一直在尝试使用 Truffle 框架部署合约,最近我一直在开发网络上测试这些合约。
我的合约非常大,当我试图将其部署到测试网时,我被指示将其拆分,这样合约就不会超过 gas 限制。不过,请记住,该合约确实以默认的 gas 限制部署到了开发网络上。
所以我取出合同的一部分,从基础衍生出另一个合同,并在其中添加了已删除的部分。我试图将其部署到开发网络以再次对其进行测试,但现在出现错误:
'Error: The contract code couldn't be stored, please check your gas amount.'
所以我采取的步骤是:
- 将我的 gasLimit 更改为 100,000,000 没有解决它
检查我的合同是否是“抽象的”
- 我对此的理解是,如果合约或其父合约具有任何没有实现的功能,则合约是抽象的。我的没有。
然后我从派生合约中删除了除构造函数之外的所有代码,但仍然出现此错误
我删除了该文件,并且部署像以前一样仅使用我的基本合同,因此父合同不能有任何未实现的功能,并且当我尝试从中派生一个空合同时它仍然不起作用(确保没有派生合同中的摘要)。
- 然后我将我的迁移文件拆分,以便单独进行迁移,但仍然没有运气。
我的父合同大约有 300 行长,所以在这里发布它没有意义 - 我知道有些人会说“它可能太大了”但是,它在开发网络上的 500 行长时部署,现在它只是250 行长,派生合约长 275 行,它不部署。
错误:
Running migration: 2_deploy_contracts.js
Replacing ERC20Token...
... 0xcae613274de1aa278e7ae5d1239f43445132a417d98765a4f227ea2439c9e4fc
ERC20Token: 0xeec918d74c746167564401103096d45bbd494b74
Replacing Crowdsale...
... 0x0ffc7291d84289c1391a81ed9f76d1e165285e3a3eadc065732aa288ea049b3a
Crowdsale: 0x0d8cc4b8d15d4c3ef1d70af0071376fb26b5669b
Saving successful migration to network...
... 0x7f351d76f61f7b801913f59b808688a2567b64933cdfdcf78bb18b0bf4e4ff69
Saving artifacts...
Running migration: 3_more_deployed_contracts.js
Deploying StagedSale...
... 0x216136bb24d317b140a247f10ec4d6791559739111a85932133cd4a66b12a1d9
Error encountered, bailing. Network state unknown. Review successful
transactions manually.
Error: The contract code couldn't be stored, please check your gas
amount.
at Object.callback
(/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329221:46)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:39618:25
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:331159:9
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:175492:11
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:314196:9
at XMLHttpRequest.request.onreadystatechange
(/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329855:7)
我的基础合约太大而无法发布,它本身就可以很好地部署,这意味着它不是抽象的。
我的派生合同是:
pragma solidity ^0.4.16;
import "./SafeMath.sol";
import "./Crowdsale.sol";
contract StagedSale is Crowdsale {
using SafeMath for uint256;
/*
* Setup the contract and transfer ownership to appropriate beneficiary
*/
function StagedSale
(
uint256 _stage1Duration,
uint256 _stage2Duration
) public {
uint256 stage1duration = _stage1Duration.mul(1 minutes);
uint256 stage2duration = _stage2Duration.mul(1 minutes);
}
我的派生合同的迁移文件:
var StagedSale = artifacts.require("./StagedSale.sol");
module.exports = function(deployer) {
const stage1Duration = 1;
const stage2Duration = 1;
deployer.deploy(StagedSale, stage1Duration, stage2Duration);
};
我在这里发布了这个问题,因为我担心这可能是 Truffle 部署的常见问题。
总而言之,我认为这与实际的气体限制没有任何关系,而是由于某种未知原因而失败并打印此错误消息。